появление картинки
Есть менюшка с картинками,при наведении на картинку в другом месте возникает её увеличенная копия,при потере курсора копия уменьшается и исчезает.
Вопрос в том,почему появляется копия,а назад никак. Попытался выводить alertом созданный объект(new_img),выводит аж 14 раз. Вот код jQuery.each(img, function(){ img.on("mouseover",zoom) });//всем картинкам подключаю событие var new_img//глобальная переменная для созданной копии function zoom (event){ var img=$(event.target) img.off("mouseover",zoom); new_img=img.clone();//создаю копию той картинки на которой произошло событие $("body").append(new_img); new_img.css("position","fixed"); new_img.css("top","100px"); new_img.css("left","300px"); new_img.css("height","30px"); new_img.css("width","30px"); new_img.css("zIndex","4"); new_img.animate({height:300,width:300},750); img.on("mouseout",zoom_out); }; function zoom_out (event){ var img=$(event.target) img.off("mouseout",zoom_out); new_img.animate({height:30,width:30},750); new_img.remove(); img.on("mouseover",zoom); } |
неужели никто ничего не подскажет
|
Dimanchik87, отформатируйте код используя теги , и было бы не плохо добавить пример, тогда посмотрю или жди кого то кто так будет смотреть)
|
Dimanchik87,
Вариант ... <!DOCTYPE HTML> <html> <head> <title>Untitled</title> <script src="http://code.jquery.com/jquery-latest.js"></script> </head> <body> <img src="http://javascript.ru/forum/images/ca_serenity/misc/logo.gif" alt=""> <script> $("body").on({"mouseenter":zoom," mouseleave":zoom_out},"img" ) ;//всем картинкам подключаю событие var new_img//глобальная переменная для созданной копии function zoom (){ if(new_img) new_img.attr({"src": $(this).attr("src")}).stop(); else new_img=$(this).clone();//создаю копию той картинки на которой произошло событие $("body").append(new_img); new_img.off("mouseenter mouseleave") new_img.css("position","fixed"); new_img.css("top","100px"); new_img.css("left","300px"); new_img.css("height","30px"); new_img.css("width","30px"); new_img.css("zIndex","4"); new_img.animate({height:300,width:300},750); }; function zoom_out (){ new_img.stop().animate({height:30,width:30},750,function () { new_img.remove() }) } </script> <img src="http://javascript.ru/img/ws_1.png" alt=""> </body> </html> |
огромное спасибо за ответ,я сделал по другому,но ваш вариант намного круче.Если кто-нибудь объяснит как вставлять код для просмотра на этот форум,покажу свой вариант
|
Dimanchik87,
Пожалуйста, отформатируйте свой код! Для этого его можно заключить в специальные теги: js/css/html и т.п., например: [js] ... ваш код... [/js] О том, как вставить в сообщение исполняемый javascript и html-код, а также о дополнительных возможностях форматирования - читайте http://javascript.ru/formatting. |
img.on("mouseover",zoom) function zoom (event){ var img=$(event.target) img.off("mouseover",zoom); new_img=img.clone(); new_img.addClass("pict1"); $("body").append(new_img); new_img.css("position","fixed"); new_img.css("top","100px"); new_img.css("left","300px"); new_img.css("height","30px"); new_img.css("width","30px"); new_img.css("zIndex","4"); new_img.animate({height:300,width:300},750); img.on("mouseout",zoom_out); }; function zoom_out (event){ var img1=$(event.target) img.off("mouseout",zoom_out); $(".pict1").animate({height:30,width:30},750,function(){$(".pict1").remove();}); img.on("mouseover",zoom); } |
подскажите как сделать,чтобы пока одна картинка не исчезла,событие на другой не происходило
|
Dimanchik87,
<!DOCTYPE HTML> <html> <head> <title>Untitled</title> <script src="http://code.jquery.com/jquery-latest.js"></script> </head> <body> <img src="http://javascript.ru/forum/images/ca_serenity/misc/logo.gif" alt=""> <script> !function (){ $("body").on({"mouseenter":zoom," mouseleave":zoom_out},"img" ) ;//всем картинкам подключаю событие var new_img, active = false; function zoom (){ if(active) return; active = true; if(new_img) { new_img.attr({"src": $(this).attr("src")}).stop(); } else { new_img=$(this).clone();//создаю копию той картинки на которой произошло событие } $("body").append(new_img); new_img.off("mouseenter mouseleave") new_img.css("position","fixed"); new_img.css("top","100px"); new_img.css("left","300px"); new_img.css("height","30px"); new_img.css("width","30px"); new_img.css("zIndex","4"); new_img.animate({height:300,width:300},750); }; function zoom_out (){ new_img.stop().animate({height:30,width:30},750,function (){ active = false; new_img.remove(); }) } }(); </script> <img src="http://javascript.ru/img/ws_1.png" alt=""> </body> </html> |
cyber,
возле run в теге html добавьте через пропуск height=500 а то картинок невидно :thanks: |
Часовой пояс GMT +3, время: 07:54. |