<tfoot id='Upkly'></tfoot>
    • <bdo id='Upkly'></bdo><ul id='Upkly'></ul>

    <small id='Upkly'></small><noframes id='Upkly'>

    <legend id='Upkly'><style id='Upkly'><dir id='Upkly'><q id='Upkly'></q></dir></style></legend>
    <i id='Upkly'><tr id='Upkly'><dt id='Upkly'><q id='Upkly'><span id='Upkly'><b id='Upkly'><form id='Upkly'><ins id='Upkly'></ins><ul id='Upkly'></ul><sub id='Upkly'></sub></form><legend id='Upkly'></legend><bdo id='Upkly'><pre id='Upkly'><center id='Upkly'></center></pre></bdo></b><th id='Upkly'></th></span></q></dt></tr></i><div id='Upkly'><tfoot id='Upkly'></tfoot><dl id='Upkly'><fieldset id='Upkly'></fieldset></dl></div>
    1. jQuery图像悬停效果

      jQuery image hover effect(jQuery图像悬停效果)

      <legend id='iR6Pt'><style id='iR6Pt'><dir id='iR6Pt'><q id='iR6Pt'></q></dir></style></legend>
        <bdo id='iR6Pt'></bdo><ul id='iR6Pt'></ul>
              <tbody id='iR6Pt'></tbody>
          • <tfoot id='iR6Pt'></tfoot>
              <i id='iR6Pt'><tr id='iR6Pt'><dt id='iR6Pt'><q id='iR6Pt'><span id='iR6Pt'><b id='iR6Pt'><form id='iR6Pt'><ins id='iR6Pt'></ins><ul id='iR6Pt'></ul><sub id='iR6Pt'></sub></form><legend id='iR6Pt'></legend><bdo id='iR6Pt'><pre id='iR6Pt'><center id='iR6Pt'></center></pre></bdo></b><th id='iR6Pt'></th></span></q></dt></tr></i><div id='iR6Pt'><tfoot id='iR6Pt'></tfoot><dl id='iR6Pt'><fieldset id='iR6Pt'></fieldset></dl></div>
            • <small id='iR6Pt'></small><noframes id='iR6Pt'>

              1. 本文介绍了jQuery图像悬停效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                I'm trying to achieve this effect with jQuery.

                I wrote some of the code, but it's buggy (move to the bottom-right corder and you'll see).
                check it out

                Basically, if there's an already-built jQuery plugin that you know of that does this, I'd be very happy using it, if not, any help with my formula would be appreciated. This is what I get for not paying attention in Maths classes :)

                Thanks in advance.

                Maikel

                解决方案

                Overall I think this is what you're looking for:

                $.fn.sexyImageHover = function() { 
                    var p = this, // parent
                        i = this.children('img'); // image
                
                    i.load(function(){
                        // get image and parent width/height info
                        var pw = p.width(),
                            ph = p.height(),
                            w = i.width(),
                            h = i.height();
                
                        // check if the image is actually larger than the parent
                        if (w > pw || h > ph) {
                            var w_offset = w - pw,
                                h_offset = h - ph;
                
                            // center the image in the view by default
                            i.css({ 'margin-top':(h_offset / 2) * -1, 'margin-left':(w_offset / 2) * -1 });
                
                            p.mousemove(function(e){
                                var new_x = 0 - w_offset * e.offsetX / w,
                                    new_y = 0 - h_offset * e.offsetY / h;
                
                                i.css({ 'margin-top':new_y, 'margin-left':new_x });
                            });
                        }
                    });
                }
                

                You can test it here.

                Notable changes:

                • new_x and new_y should be divided by the images height/width, not the container's height/width, which is wider.
                • this is already a jQuery object in a $.fn.plugin function, no need to wrap it.
                  • i and p were also jQuery objects, no need to keep wrapping them
                • no need to bind mousemove on mouseenter (which rebinds) the mousemove will only occur when you're inside anyway.

                这篇关于jQuery图像悬停效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Move link image 5px up on hover(悬停时将链接图像向上移动 5px)
                How do I inspect CSS pseudo classes with firebug?(如何使用 firebug 检查 CSS 伪类?)
                Why doesn#39;t CSS hover work on table rows when the cells inside the rows have class names?(当行内的单元格具有类名时,为什么 CSS 悬停在表格行上不起作用?)
                Hover image - display div over it(悬停图像 - 在其上显示 div)
                How to apply a CSS class on hover to dynamically generated submit buttons?(如何在悬停时将 CSS 类应用于动态生成的提交按钮?)
                Differences between CSS3 :hover and :focus?(CSS3 :hover 和 :focus 的区别?)
              2. <small id='KkszL'></small><noframes id='KkszL'>

                  • <legend id='KkszL'><style id='KkszL'><dir id='KkszL'><q id='KkszL'></q></dir></style></legend>
                    <tfoot id='KkszL'></tfoot>
                      <tbody id='KkszL'></tbody>
                    1. <i id='KkszL'><tr id='KkszL'><dt id='KkszL'><q id='KkszL'><span id='KkszL'><b id='KkszL'><form id='KkszL'><ins id='KkszL'></ins><ul id='KkszL'></ul><sub id='KkszL'></sub></form><legend id='KkszL'></legend><bdo id='KkszL'><pre id='KkszL'><center id='KkszL'></center></pre></bdo></b><th id='KkszL'></th></span></q></dt></tr></i><div id='KkszL'><tfoot id='KkszL'></tfoot><dl id='KkszL'><fieldset id='KkszL'></fieldset></dl></div>
                        • <bdo id='KkszL'></bdo><ul id='KkszL'></ul>