Msc Final Project

Mouseover to set the image as background (js)

I was trapped in this tiny little bug for several hours: a href=”#” is a must or it will refresh the whole site, then you will never change the background image, never!


<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>/*this should be an independent CSS*/
  body{background:#b8c2f8}
  img{width:300px;height:300px;}
</style>
</head>

<body>
  
tc
function basename(url){ var loc = url.lastIndexOf("/")+1;//get the direct name of image return url.substr(loc); } function changepic(obj){ document.body.style.backgroundImage="url('images/"+basename(obj.src)+"')"; } function returnpic(obj){ document.body.style.background="#b8c2f8";//if mouseout then return to its normal bgcolor } </body> </html>  
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s