如何使用jQuery将鼠标悬停70%以上

时间:2010-11-17 11:38:30

标签: jquery colorbox

我希望jQuery colorbox在鼠标悬停时打开图片并在mouseout上关闭。 你能建议我怎么做吗?

2 个答案:

答案 0 :(得分:2)

这可以让你开始......

HTML

<img src="a.jpg" alt="b" />

的jQuery

$('img').hover(function() {
    $(this).stop().animate({ width: '170%' }, 500);
}, function() {
    $(this).stop().animate({ width: '100%' }, 500);
});

答案 1 :(得分:0)

我会做这样的事情:

 $(function(){
  function fatOnHover($elements, zoomSize, animationSpeed){
  $elements.each(function(i){
     var $wrap, height, width, bigWidth, bigHeight, $that = $(this);
     height = $that.height();
     width = $that.width();
     bigWidth = (width / 100) * zoomSize;
     bigHeight = (height / 100) * zoomSize;
      $wrap = "<div style='z-index: " + (10000-i) +";width: " + width + "px; height: " + height + "px; position: relative; float: left'></div>",
      $that.data({"width": width, "height": height, "bigWidth": bigWidth, "bigHeight": bigHeight})
          .wrap($wrap)
   }).hover(
     function(){
        var $that = $(this);
        $that.stop().animate({"width": $that.data("bigWidth"), "height": $that.data("bigHeight")}, animationSpeed)
     },
     function(){
        var $that = $(this);
        $that.stop().animate({"width": $that.data("width"), "height": $that.data("height")}, animationSpeed)
     }
  ).css("position", "absolute")
   }


fatOnHover($('img'), 120, 300)
})

您可以在此处测试:http://jsfiddle.net/GHuNF/1/