简体   繁体   中英

How to achieve hover effect using javascript?

I have 3 bullet images. 1 for active, 1 for hover and 1 for the rest links.

Here is my code:

<a href="#" class="toc selected" rel="2"><img src="images/othersdefdot.png" onclick="funcCaller('fund', 'images/reddot.png', 'local', 'images/othersdefdot.png', 'youthgames', 'images/othersdefdot.png')" name="fund"></a>

How to achieve hover effect in this link?

Check the demo page here

<a href="#" class="toc selected" onMouseover="showPic1()" onMouseout="showPic2()">
    <img id="link_img" src="/images/othersdefdot.png" />
</a>

Javascript:

function showPic1() {
    document.getElementById('link_img').src = "/images/img1.png";
}

function showPic2() {
    document.getElementById('link_img').src = "/images/img2.png";
}

I'm not exactly sure what you're asking, but you can use the onmouseover property.

<a href="#" class="toc selected" rel="2"><img src="images/othersdefdot.png" onclick="funcCaller('fund', 'images/reddot.png', 'local', 'images/othersdefdot.png', 'youthgames', 'images/othersdefdot.png')" onmouseover="javascriptFunction()" name="fund"></a>

You must be looking at the jQuery scrollable here:http://flowplayer.org/tools/demos/scrollable/plugins/index.html

I think this is what you want.

if its just for hover effect, there is no need to use javascript. You could just use css:

a img:hover{
   /*change background*/ 
}

however if you insist, you could attach event handler onmousedown to it. hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM