jqueryʵÏÖͼƬ·Å´ó¾µ¹¦ÄÜ
ʵÏÖÔÀí£º
¡¡¡¡ÕâÀïÓõ½ÁËÁ½ÕÅͼƬ£¬Ò»ÕÅСͼ£¬Ò»ÕÅ´óͼ¡£½«´óͼÉèÖÃΪ·Å´ó¾µµÄ±³¾°Í¼Æ¬£¬µ±Êó±êÔÚСͼÉÏÒƶ¯Ê±£¬Í¬Ê±¿ØÖƱ³¾°´óͼÔÚ·Å´ó¾µÖеÄλÖá£Á½ÕÅͼƬ´óС×îºÃÊǵȱÈÀýµÄ£¬ÕâÑù²ÅÄÜ´ïµ½×î¼ÑЧ¹û¡£µ±Ã»Óдóͼʱ£¬ÔòĬÈÏΪСͼ±¾Éí£¬ÕâʱÓÉÓÚÁ½ÕÅͼƬ´óСһÑù£¬Òò´Ë·Å´ó¾µÐ§¹û²»Ã÷ÏÔ£¬¾Í¸úû·Å´óÊÇÒ»ÑùµÄ¡£
¡¡¡¡´Ë²å¼þÓõ½ÁËhtml5£¬css3µÄһЩÊôÐÔ£¬ie8¼°ÒÔÏ°汾²»¼æÈÝ£¬·Å´ó¾µÊÇ·½Ðεġ£
ÔËÐÐЧ¹û½ØͼÈçÏ£º
¾ßÌå´úÂëÈçÏ£º
(function () { $.fn.Magnifier = function (options) { //ĬÈϲÎÊýÉèÖà var settings = { diameter: 150, //·Å´ó¾µµÄÖ±¾¶´óС borderWidth: 2, //·Å´ó¾µ±ß¿ò´óС borderColor: "white", //·Å´ó¾µ±ß¿òÑÕÉ« backgroundImg: "../img/111.jpg" //·Å´ó¾µÄÚµÄͼƬ£¨¼´´óͼ£© }; //ºÏ²¢²ÎÊý if (options) $.extend(settings, options); //Á´Ê½ÔÔò return this.each(function () { //´æ´¢µ±Ç°¶ÔÏó var root = $(this); //µ±Ç°¶ÔÏó¿í¸ß var WRoot = root.width(); var HRoot = root.height(); //Æ«ÒÆÁ¿ left ºÍ top var offset = root.offset(); //·Å´ó¾µÑùʽ var style = "background-position: 0px 0px;background-repeat: no-repeat;float: left;"; style += "position: absolute;box-shadow:0 0 5px #777, 0 0 10px #aaa inset;display: none;"; style += "width: " + String(settings.diameter) + "px;height: " + String(settings.diameter) + "px;"; style += "border-radius: " + String(settings.diameter / 2 + settings.borderWidth) + "px;"; style += "border: " + String(settings.borderWidth) + "px solid " + settings.borderColor + ";"; //´´½¨·Å´ó¾µ var magnifier = $("<div></div>").appendTo(root.parent()); //ͼƬ£¨µ±Ã»Óдóͼʱ£¬ÎªÐ¡Í¼±¾Éí£© var backgroundImg = settings.backgroundImg ? settings.backgroundImg : root.attr("src"); //½«Í¼Æ¬·ÅÈë·Å´ó¾µÄÚ magnifier.css({ backgroundImage: "url('" + backgroundImg + "')" }); //Ëõ·Å±ÈÀý var WRatio = 0; //¿í¶È var HRatio = 0; //¸ß¶È //ͼƬ¼ÓÔØÍ꣬¼ÆËãËõ·Å±ÈÀý //ÓÉÓÚͼƬԱ¾²»ÔÚDOMÎĵµÀÒò´ËÒ³Ãæ¼ÓÔØʱ²»»á´¥·¢loadʼþ£¬Òò´ËҪͨ¹ýÖ´ÐÐappendToÀ´´¥·¢loadʼþ $("<img src='" + backgroundImg + "' />").load(function () { WRatio = $(this).width() / WRoot; HRatio = $(this).height() / HRoot; }).appendTo(root.parent()); //·Å´ó¾µ¼°Æä±³¾°Í¼Æ¬Î»ÖÿØÖÆ function Position(e) { var LPos = parseInt(e.pageX - offset.left); var TPos = parseInt(e.pageY - offset.top); //ÅжÏÊó±êÊÇ·ñÔÚͼƬÉÏ if (LPos < 0 || TPos < 0 || LPos > WRoot || TPos > HRoot) { magnifier.hide(); //²»ÔÚÒþ²Ø·Å´ó¾µ } else { magnifier.show(); //·´Ö®ÏÔʾ·Å´ó¾µ //¿ØÖÆ·Å´ó¾µÄÚ±³¾°Í¼Æ¬µÄλÖà £¨settings.diameter / 2£©°ë¾¶ LPos = String(((e.pageX - offset.left) * WRatio - settings.diameter / 2) * (-1)); TPos = String(((e.pageY - offset.top) * HRatio - settings.diameter / 2) * (-1)); magnifier.css({ backgroundPosition: LPos + 'px ' + TPos + 'px' }); //¿ØÖÆ·Å´ó¾µ±¾ÉíλÖà LPos = String(e.pageX - settings.diameter / 2); TPos = String(e.pageY - settings.diameter / 2); magnifier.css({ left: LPos + 'px', top: TPos + 'px' }); } } //·Å´ó¾µ magnifier.mousemove(Position); //µ±Ç°¶ÔÏó root.mousemove(Position); }); }; })();
ʵÀýDEMOÈçÏ£º
<!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>CSS3+jQueryͼÏñ·Å´ó¾µÐ§¹û</title> <style type="text/css"> body { background-color: Black; } .box { width: 700px; margin: 50px auto; } </style> </head> <body> <div> ¡¡¡¡¡¡¡¡ <!--Сͼ--> <img alt="" src="../img/222.gif" /> </div> <script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <script src="../Scripts/jquery.similar.magnifier.js" type="text/javascript"></script> <script type="text/javascript"> $("#img_02").Magnifier(); </script> </body> </html>
¹ØÓÚjqueryʵÏÖͼƬ·Å´ó¾µ¹¦ÄܵÄÄÚÈݾͽéÉܵ½ÕâÀϣÍû´ó¼Ò×ÐϸÑо¿£¬Ñ§ÒÔÖÂÓá£
ÍƼöÎÄÕÂ
±¾Ò³ÄÚÈÝ°æȨ¹éÊôΪÔ×÷Õߣ¬ÈçÓÐÇÖ·¸ÄúµÄȨÒ棬Çë֪ͨÎÒÃÇɾ³ý¡£
jqueryʵÏÖ¼ÓÔؽø¶ÈÌõÌáʾЧ¹û - 2015-11-24 14:11:05
±¾ÎÄʵÀý½²ÊöÁËjqueryʵÏÖ¼ÓÔؽø¶ÈÌõÌáʾЧ¹û´úÂë¡£·ÖÏí¸ø´ó¼Ò¹©´ó¼Ò²Î¿¼¡£¾ßÌåÈçÏ£º ÔËÐÐЧ¹û½ØͼÈçÏ£º ¾ßÌå´úÂëÈçÏ£º !DOCTYPE htmlhtml head meta charset="utf-8" title½ø¶ÈÌõ/title script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.4.1/jquery.min.js"/script /head body div /div /b
nodejs³õ²½ÌåÑéƪ - 2015-11-24 14:11:04
Ç°ÑÔ£ºÐ´ÕâƪÎÄÕµÄÓÉÀ´£º 1.Ç°¶Îʱ¼äµ¥Î»ÓÐÐÂÏîÄ¿Æô¶¯£¬·þÎñ¶ËÒª×öµÄ¹¤×÷²»¶àÒ²²»ËãÂé·³£¬¾ÍÊÇ´¦ÀíһЩÖмä²ãµÄ·þÎñ£¬¶øÇÒÎÒÃÇÍŶÓÀïÃæ¸ö¸ö¶¼»áJavaScript£¬Áìµ¼¾Í¾ö¶¨ÊÔÊÔ·þÎñÆ÷¶ËµÄJavaScript£¬½á¹û±¾ÈËÓÐÐÒ±»ÅÉÈ¥Ñо¿Á˼¸ÌìNode£¬»³×ż¦¶³µÄÐÄÇ鿪ʼÁËnode.jsµÄƪÕ£¬ÕâƪÎÄÕÂÒ²¾ÍÊÇΪÕ⼸ÌìÑо¿µÄ×ܽᡣ 2.Ò»¸öJavaScript¹¤³ÌʦÈç¹ûûÌý¹ýnode.jsÄÇôÎÒÏëÄãÊDz»ÊÇ´í¹ýÁËʲô£¬Ã¿¸öÓÅÐãµÄÇ°¶Ë¹¤³Ìʦ¶¼ÓбØҪȥÁ˽âºǫ́´¦ÀíÁ÷³Ì£¬ÄÇôÈç¹ûÓÖÄÜ´ÓJavaScript³ö·¢£¬Æñ²»ÊÇÒ»¼þºÜÃÀ
- 2015-11-23 18:11:33
JavaScript¿ª·¢¾µä¼¼ÇÉ·ÖÏí¸ø´ó¼Ò£º 1¡¢Ê×´ÎΪ±äÁ¿¸³ÖµÊ±Îñ±ØʹÓÃvar¹Ø¼ü×Ö ±äÁ¿Ã»ÓÐÉùÃ÷¶øÖ±½Ó¸³ÖµµÃ»°£¬Ä¬ÈÏ»á×÷Ϊһ¸öеÄÈ«¾Ö±äÁ¿£¬Òª¾¡Á¿±ÜÃâʹÓÃÈ«¾Ö±äÁ¿¡£ 2¡¢Ê¹ÓÃ===È¡´ú== ==ºÍ!=²Ù×÷·û»áÔÚÐèÒªµÄÇé¿öÏÂ×Ô¶¯×ª»»Êý¾ÝÀàÐÍ¡£µ«===ºÍ!==²»»á£¬ËüÃÇ»áͬʱ±È½ÏÖµºÍÊý¾ÝÀàÐÍ£¬ÕâҲʹµÃËüÃÇÒª±È==ºÍ!=¿ì¡£ [10] === 10 // is false [10] == 10 // is true '10' == 10 // is true '10' === 10 // is false
jqueryʵÏÖselectÑ¡Ôñ¿òÄÚÈÝ×óÓÒÒƶ¯´úÂë·ÖÏí - 2015-11-23 18:11:32
¡¡