Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3429046
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:02:03+00:00 2026-05-18T07:02:03+00:00

I’m working in a site with the plugin jq.imghover1.1.js for jquery. The plugin works

  • 0

I’m working in a site with the plugin jq.imghover1.1.js for jquery.
The plugin works great almost in any circumstances, but I did a position:absolute for a div that contains the images that will be affected by the plugin and now when the plugin fade the hover images in, they do it far to the right of the original button.

The Code:

<html>
<head>
<style type="text/css">

.container {
width: 1004px;

margin: 0 auto;
display: table;}

.top {

height: 140px;
position: absolute;
top: 0px;
left: 0px;}

<script type="text/javascript"

$(document).ready(function(){
        $('img.on').imghover({suffix: '_b',fade: true,fadeSpeed: 400});
    });

</script>
</head>
<body>

<div class="container top">
    <div class="mainmenu">
    <img alt="acerca de" height="53" src="images/mm-acercade.jpg" width="117" class="on" />
    </div>
</div>
</body>
</html>

The JS:

/**
 *  jquery.popupt
 *  (c) 2008 Semooh (http://semooh.jp/)
 *
 *  Dual licensed under the MIT (MIT-LICENSE.txt)
 *  and GPL (GPL-LICENSE.txt) licenses.
 *
 **/
(function($){
 $.fn.extend({
  imghover: function(opt){
   return this.each(function() {
        opt = $.extend({
            prefix: '',
            suffix: '_o',
            src: '',
            btnOnly: true,
            fade: false,
            fadeSpeed: 500
          }, opt || {});

        var node = $(this);
    if(!node.is('img')&&!node.is(':image')){
          var sel = 'img,:image';
          if (opt.btnOnly) sel = 'a '+sel;
          node.find(sel).imghover(opt);
          return;
        }

        var orgImg = node.attr('src');

        var hoverImg;
        if(opt.src){
          hoverImg = opt.src;
        }else{
          hoverImg = orgImg;
          if(opt.prefix){
            var pos = hoverImg.lastIndexOf('/');
            if(pos>0){
              hoverImg = hoverImg.substr(0,pos-1)+opt.prefix+hoverImg.substr(pos-1);
            }else{
              hoverImg = opt.prefix+hoverImg;
            }
          }
          if(opt.suffix){
            var pos = hoverImg.lastIndexOf('.');
            if(pos>0){
              hoverImg = hoverImg.substr(0,pos)+opt.suffix+hoverImg.substr(pos);
            }else{
              hoverImg = hoverImg+opt.suffix;
            }
          }
        }

        if(opt.fade){
          var offset = node.offset();
          var hover = node.clone(true);
          hover.attr('src', hoverImg);
          hover.css({
            position: 'absolute',
            left: offset.left,
            top: offset.top,
            zIndex: 1000
          }).hide().insertAfter(node);
          node.mouseover(
            function(){
              var offset=node.offset();
              hover.css({left: offset.left, top: offset.top});
              hover.fadeIn(opt.fadeSpeed);
              node.fadeOut(opt.fadeSpeed,function(){node.show()});
            }
          );
          hover.mouseout(
            function(){
              node.fadeIn(opt.fadeSpeed);
              hover.fadeOut(opt.fadeSpeed);
            }
          );
        }else{
          node.hover(
            function(){node.attr('src', hoverImg)},
            function(){node.attr('src', orgImg)}
          );
        }
   });
  }
 });
})(jQuery);

The whole problem is that when you hover the button, the imghover hovers an image on top of the original one, calculating the distance from left of the screen to position the hovering image. When you do a position:absolute div as container for the images that will be affected by the imghover, the calculations for the positioning of the hovering image keeps the same unless you add a left: Xpx, which helps the imghover calculating the left distance, but as you could see, the container has no left: Xpx declared so the imghover take for granted the position from the left of the screen, then adds it to its declaration and I end up with a hovering image about 300px far right than needed.

Any idea will be great!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T07:02:04+00:00Added an answer on May 18, 2026 at 7:02 am

    I haven’t realized no one has answered this question.
    In case there’s someone who may find it useful, here it is:

    In the original JS, change this:

    if(opt.fade){
              // change from this: var offset = node.offset();
              var offset = node.position();
              // so the positioning is absolute related to the parent;
              var hover = node.clone(true);
              hover.attr('src', hoverImg);
    

    When I used offset(), it calculates the offset form the window left and top sides, so the coordinates of the image(s) went far down and right.

    When using position() it takes the left and top from the offset parent so it shouldn’t go far down or right and do the fade in the same place as the original image.

    But in the jq.imghover1.1.js there’s another thing to change:

    function(){
                  var offset=node.offset();
    // original   hover.css({left: offset.left, top: offset.top});
                  hover.css({left: offset, top: offset});
    // if you keep the .left and .top data then the positioning will fail.
                  hover.fadeIn(opt.fadeSpeed);
    

    This could become a better implementation of this plugin, I mean, adding the position or offset value for the imghover, as a parameter when you call the script. I’ll try to do it myself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to construct a data frame in an Rcpp function, but when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.