大佬教程收集整理的这篇文章主要介绍了如何使用jquery将删除图像/图标附加到div内的图像,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我如何实现这一目标?
这是我上传和附加到div容器的方式:
<script type="text/javascript"> $(function () { document.getElementById('Nextbutton').style.visibility = "hidden"; // show $("#uploader").plupload({ // General setTings runtimes: 'gears,flash,silverlight,browserplus,html5',url: 'Test.aspx',max_file_size: '10mb',max_file_count: 20,chunk_size: '1mb',unique_names: true,filters: [ { title: "Image files",extensions: "jpg,gif,png" },{ title: "Zip files",extensions: "zip" } ],flash_swf_url: 'js/plupload.flash.swf',silverlight_xap_url: 'js/plupload.silverlight.xap' }); $('form').submit(function (E) { var uploader = $('#uploader').plupload('getUploader'); if (uploader.files.length > 0) { uploader.bind('StateChanged',function () { if (uploader.files.length === (uploader.@R_537_10586@l.uploaded + uploader.@R_537_10586@l.Failed)) { $('form')[0].submit(); } }); uploader.start(); } else //alert('You must at least upload one file.'); return false; }); var uploader = $('#uploader').plupload('getUploader'); uploader.bind('FilesAdded',function (up,files) { // jQuery('#container a').html(''); $('#container > *').remove(); var i = 0; while (i++ < up.files.length) { var ii = i; while (ii < up.files.length) { if (up.files[i - 1].name == up.files[ii].Name) { $.msgBox({ title: "Ooops",content: "There is already an image with the same filename and cAnnot be added.",type: "error",showButtons: true,opacity: 0.9,autoClose: false }); uploader.removeFile(up.files[ii]); } else { ii++; } } } if (i > 20) { $.msgBox({ title: "Info",content: "Uuh! Please don't put me any more files.<br>Maximum Upload limit is only 20 Images.<br>Rest of the Images will be removed.",type: "info",autoClose: false }); $('#uploader_browse').hide(); } }); uploader.bind('FilesRemoved',files) { if (up.files.length < 20) { $('#uploader_browse').fadeIn("slow"); } }); uploader.bind('FileUploaded',file,res) { $('#container').append("<div class='container a'><a href='uploads/" + document.getElementById("currentDirectory").value + "/" + file.name + "' rel='prettyPhoto' target='blank'><img src='uploads/" + document.getElementById("currentDirectory").value + "/" + file.name + "' width='64' height='64'/></a></div>"); var $imageContainers = $('#container a'); $imageContainers.each(function (indeX) { $(this).delay(index * 50).fadeTo(400,0.5); }); $imageContainers.mouSEOver(function () { $(this).css('opacity',1); $(this).find('span.del').show(); }); $imageContainers.mouSEOut(function () { $(this).css('opacity',0.5); $(this).find('span.del').hide(); }); if (uploader.files.length === (uploader.@R_537_10586@l.uploaded + uploader.@R_537_10586@l.Failed)) { document.getElementById('Nextbutton').style.visibility = "visible"; // show showStickysuccessToast(); } uploader.removeFile(filE); }); }); function randomString(length) { var chars = '0123456789ABCDEFGHIJKLMNOPQRstuVWXTZabcdefghiklmnopqrstuvwxyz'.split(''); if (!length) { length = Math.floor(Math.random() * chars.length); } var str = ''; for (var i = 0; i < length; i++) { str += chars[Math.floor(Math.random() * chars.length)]; } return str; } </script>
这是我显示图像的div:
<div id="container"> </div>
HTML
<div id="container"> <div class="image" id="image1" style="BACkground-image:url(http://lorempixel.com/100/100/abstract);"> <a href="#" class="@R_874_9421@e">@R_874_9421@e</a> </div> <div class="image" id="image2" style="BACkground-image:url(http://lorempixel.com/100/100/food);"> <a href="#" class="@R_874_9421@e">@R_874_9421@e</a> </div> <div class="image" id="image3" style="BACkground-image:url(http://lorempixel.com/100/100/peoplE);"> <a href="#" class="@R_874_9421@e">@R_874_9421@e</a> </div> <div class="image" id="image4" style="BACkground-image:url(http://lorempixel.com/100/100/technics);"> <a href="#" class="@R_874_9421@e">@R_874_9421@e</a> </div> </div>
CSS
#container { overflow:auto; } .image { width:100px;height:100px;float:left;position:relative; } a.@R_874_9421@e { display:none;position:absolute;top:0;right:0;width:30px;height:30px;text-indent:-999px;BACkground:red; } .image:hover a.@R_874_9421@e { display:block; }
jQuery的/ JavaScript的
$(document).ready(function(){ $('a.@R_874_9421@e').on('click',function(E){ e.preventDefault(); imagEID = $(this).closest('.image')[0].id; alert('Now @R_874_9421@ing "'+imagEID+'"'); $(this).closest('.image') .fadeTo(300,function(){ $(this) .animate({width:0},200,function(){ $(this) .remove(); }); }); }); });
以上是大佬教程为你收集整理的如何使用jquery将删除图像/图标附加到div内的图像全部内容,希望文章能够帮你解决如何使用jquery将删除图像/图标附加到div内的图像所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。