how to get a hover effect with jQuery?? Its not wo

2020-05-03 12:37发布

I'm trying to get hover effect similar to this example. But couldn't get it. Here is the link

7条回答
地球回转人心会变
2楼-- · 2020-05-03 12:52

It looks like the code copied to the new page is missing the position:relative, which would fix the issue. Now, for security, you may want to limit the height of the block and set the overflow to hidden.

查看更多
家丑人穷心不美
3楼-- · 2020-05-03 12:53

Your image is 404ing due to your css rule for .project .thumb a{}
It points to "images/snbw_thumb.jpg" but you'll likely want to use "/images/snbw_thumb.jpg"

Bad URL : http://dragonfly.zymichost.com/css/images/snbw_thumb.jpg

Good URL : http://dragonfly.zymichost.com/images/snbw_thumb.jpg

(Also, it looks like your pages aren't really serving 404s as the bad URL )

Hope this helps

-Chris

查看更多
迷人小祖宗
4楼-- · 2020-05-03 12:59

On test page this is your css:

.thumb {
list-style: none;
float: left;
background: white;
width: 250px;
position: relative;/* this makes all the difference */
}

On production page:

.project .thumb {
width: 260px;
float: left;
}

Add position: relative to .project .thumb

查看更多
ゆ 、 Hurt°
5楼-- · 2020-05-03 13:02

Your <script> tag references a jquery-1.2.6.min.js which does not exist. Put that file in the same directory as hovereffect.html on your web server.

Or, perhaps even better, get JQuery from Google Libraries:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
查看更多
来,给爷笑一个
6楼-- · 2020-05-03 13:02

The reason it's not working is because you are missing a css property

.project .thumb img {position:absolute}

notice that you have this line in your test page.

the way you are using jQuery's animate function to change the position of the top image {top:150px}, so you need make it absolutely position for this to work.

Also the .project .thumb a line is missing it's width and height.

Also note that if you just add that line, the affect still won't be the way you expect. Create an outer div with an overflow:hidden.

查看更多
神经病院院长
7楼-- · 2020-05-03 13:02

Its because in your real project your css is in the /css directory. So your CSS style is looking for /css/images/snbw_thumb.jpg which doesn't exist. Change your CSS style to ../images/snbw_thumb.jpg and it should fix it.

查看更多
登录 后发表回答