/    Sign up×
Community /Pin to ProfileBookmark

Remove onclick to no click needed

This is the coding I have. My employer would like to have the background image grow from small to big like in powerpoint. I have it to this so far. I can get the image to grow. Just need to do it without the onclick command so it is auto.

<script type=”text/javascript”>

var links = document.getElementsByTagName(‘a’);

for (var i = 0; i < links.length; i++)
if (links[i].className == ‘livethumbnail’)
{
var img = links[i].getElementsByTagName(‘img’)[0];
img.state = ‘small’;
img.smallSrc = img.getAttribute(‘src’);
img.smallWidth = parseInt(img.getAttribute(‘width’));
img.smallHeight = parseInt(img.getAttribute(‘height’));
img.largeSrc = links[i].getAttribute(‘href’);
img.largeWidth = parseInt(img.getAttribute(‘largewidth’));
img.largeHeight = parseInt(img.getAttribute(‘largeheight’));
img.ratio = img.smallHeight / img.smallWidth;
links[i].onclick = scale;
}

function scale()
{
var img = this.getElementsByTagName(‘img’)[0];
img.src = img.smallSrc;

if (! img.preloaded)
{
img.preloaded = new Image();
img.preloaded.src = img.largeSrc;
}

var interval = window.setInterval(scaleStep, 10);
return false;

function scaleStep()
{
var step = 10;
var width = parseInt(img.getAttribute(‘width’));
var height = parseInt(img.getAttribute(‘height’));

if (img.state == ‘small’)
{
width += step;
height += Math.floor(step * img.ratio);

img.setAttribute(‘width’, width);
img.setAttribute(‘height’, height);

if (width > img.largeWidth – step)
{
img.setAttribute(‘width’, img.largeWidth);
img.setAttribute(‘height’, img.largeHeight);
img.setAttribute(‘src’, img.largeSrc);
window.clearInterval(interval);
img.state = ‘large’;
}
}

}
}

</script>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@fhack2authorMar 27.2009 — Why is it no body on any forum I ask replying. I just need to find out how to do this. My counslor I'm making the website for keeps bugging me and I don't know how to do it. I got that fair and no replies on how to fix.
Copy linkTweet thisAlerts:
@Angry_Black_ManMar 27.2009 — bind the "scale" function to the "window.onload" event rather than the link's onclick event. then, instead of having the "scale" function search for an image to grow, hardcode a certain image to grow by assigning it an ID and referincing the object by "getElementById".

if that doesnt make sense, however, you may want to brush up on your JS! tell that counselor that she can't bug you about something you may not be qualified to pump out?
×

Success!

Help @fhack2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...