0
我正在嘗試使用watermark.js插件,但只想在帶有水印的圖像上單擊事件。也就是說,我不希望所有的圖像都具有僅具有點擊事件或更改事件的水印。我所做的是啓動水印插件,並在點擊提交事件中爲圖像添加類「水印」,但它不起作用。任何人都可以請指導我如何去做。嘗試在單擊事件上使用watermark.js
<!doctype html>
<html lang="en-us">
<head>
<title>watermark.js basic demo</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
</head>
<body style="margin:0;padding:0;">
<div style="width:500px;position:relative;margin:auto;">
<h1>watermark.js basic demo</h1><a href="http://www.patrick-wied.at/static/watermarkjs/">Back to watermark.js</a> The first and the third image will get a predefined watermark:
<img src="img/1.png" class="watermark" />
<img src="img/2.png" id="water" />
<img src="img/3.png" id="water" />
</div>
<form action="">
<input type="submit" value="Submit">
</form>
<!-- Look at the configuration -->
<script src="watermark.js"></script>
<script>
var load = false;
window.onload = function() {
if (!load) {
wmark.init({
/* config goes here */
"position": "top-left", // default "bottom-right"
"opacity": 100, // default 50
"className": "watermark", // default "watermark"
"path": "water.png"
});
load = true;
}
}
</script>
<script>
$(document).ready(function() {
$("form").submit(function() {
$("img").addClass("watermark");
});
});
</script>
</body>
</html>
謝謝@magreenberg – Fearlessinc