December 1, 201213 yr Im trying to get this 'scroll-to' jquery script to work but its not happening for some reason. Here is the tutorial http://gazpo.com/2012/03/horizontal-content-scroll/ and here is my html nd css. Any ideas? html <!DOCTYPE html> <html> <head> <title>PW</title> <link rel="stylesheet" type="text/css" href="style/style.css"> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script> function goto(id, t){ //animate to the div id. $(".contentBoxWrapper").animate({"left": -($(id).position().left)}, 600); // remove "active" class from all links inside #nav $('#nav a').removeClass('active'); // add active class to the current link $(t).addClass('active'); } </script> </head> <body> <!-- Header Section --> <div id="headerContainer"> <div id="header"><a href="#" id="logo"><img src="img/logo.png" /></a></div> </div> <!-- Navigation Section --> <div id="nav"> <div id="navHome"><a class="active" href="#" onclick="goto('#home', this); return false"><img src="img/navHome.png" /></a></div> <div id="navShop"><a href="#" onclick="goto('#shop', this); return false"><img src="img/navShop.png" /></a></div> <div id="navContact"><a href="#" onclick="goto('#contact', this); return false"><img src="img/navContact.png" /></a></div> </div> <!-- Content Section --> <div id="content"> <div class="contentBoxWrapper"> <div id="home" class="contentBox"> <h1>Home</h1> <p>This will be the home page</p> </div> <div id="shop" class="contentBox"> <h1>Shop</h1> <p>This will be the shop page</p> </div> <div id="contact" class="contentBox"> <h1>Contact</h1> <p>This will be the contact page</p> </div> </div> </div> </div> <div id="title"></div> <div id="controlContainer"></div> </body> </html> css * { margin: 0; padding: 0; } html { padding: 10px; background: #FFF; } body { background-image: url("../img/bg.png"); } /* ---------- Header Section ---------- */ #headerContainer { height: 57px; background: #FFF; } #header { width: 940px; height: 57px; padding: 0px 20px; margin: 0 auto; } #header #logo:hover { opacity:0.8; } a img { border: none; } /* ---------- Navigation Section ---------- */ #nav { width: 940px; height: 30px; padding: 0px 20px; margin: 0 auto; position: relative; } #navHome { width: 116px; height: 42px; position: absolute; top: -4px; left: 450px; } #navShop { width: 116px; height: 42px; position: absolute; top: -4px; left: 620px; } #navContact { width: 182px; height: 42px; position: absolute; top: -4px; left: 780px; } #navHome:hover { opacity:0.8; } #navShop:hover { opacity:0.8; } #navContact:hover { opacity:0.8; } #title { height: 101px; margin: 69px 0px 0px 0px; border-bottom: solid 50px #FFF; } /* ---------- Control Section ---------- */ #controlContainer { width: 940px; height: 300px; padding: 0px 20px; margin: 0 auto; } #content{ overflow: hidden; -moz-box-shadow: 0 0 2px 2px #ccc; -webkit-box-shadow: 0 0 2px 2px #ccc; box-shadow: 0 0 2px 2px #ccc; } .contentBoxWrapper{ position: relative; left: 0; width: 900px; } .contentBox{ width: 580px; float: left; padding: 10px; background: #fff; } #nav a.active { font-weight:bold; }
December 1, 201213 yr i dont think your linking to jquery correctly //ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js change to http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
December 2, 201213 yr Please, upload your code and share link here.. so easily, we could fix your issue
December 2, 201213 yr <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>PW</title> <link rel="stylesheet" type="text/css" href="style/style.css"> <style> * { margin: 0; padding: 0; } html { padding: 10px; background: #FFF; } body { background-image: url("../img/bg.png"); } /* ---------- Header Section ---------- */ #headerContainer { height: 57px; background: #FFF; } #header { width: 940px; height: 57px; padding: 0px 20px; margin: 0 auto; } #header #logo:hover { opacity:0.8; } a img { border: none; } /* ---------- Navigation Section ---------- */ #nav { width: 940px; height: 30px; padding: 0px 20px; margin: 0 auto; position: relative; } #navHome { width: 116px; height: 42px; position: absolute; top: -4px; left: 450px; } #navShop { width: 116px; height: 42px; position: absolute; top: -4px; left: 620px; } #navContact { width: 182px; height: 42px; position: absolute; top: -4px; left: 780px; } #navHome:hover { opacity:0.8; } #navShop:hover { opacity:0.8; } #navContact:hover { opacity:0.8; } #title { height: 101px; margin: 69px 0px 0px 0px; border-bottom: solid 50px #FFF; } /* ---------- Control Section ---------- */ #controlContainer { width: 940px; height: 300px; padding: 0px 20px; margin: 0 auto; } #content{ overflow: hidden; -moz-box-shadow: 0 0 2px 2px #ccc; -webkit-box-shadow: 0 0 2px 2px #ccc; box-shadow: 0 0 2px 2px #ccc; width:600px; margin:0px auto; } .contentBoxWrapper{ position: relative; left: 0; width: 3000px; } .contentBox{ width: 580px; float: left; padding: 10px; background: #fff; } #nav a.active { font-weight:bold; } </style> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script> function goto(id, t) { //animate to the div id. $(".contentBoxWrapper").animate({"left": -($(id).position().left)}, 600); // remove "active" class from all links inside #nav $('#nav a').removeClass('active'); // add active class to the current link $(t).addClass('active'); } </script> </head> <body> <!-- Header Section --> <div id="headerContainer"> <div id="header"><a href="#" id="logo"><img src="img/logo.png" /></a></div> </div> <!-- Navigation Section --> <div id="nav"> <div id="navHome"><a class="active" href="#" onclick="goto('#home', this); return false"><img src="img/navHome.png" />home</a></div> <div id="navShop"><a href="#" onclick="goto('#shop', this); return false"><img src="img/navShop.png" />shop</a></div> <div id="navContact"><a href="#" onclick="goto('#contact', this); return false">contact<img src="img/navContact.png" /></a></div> </div> <!-- Content Section --> <div id="content"> <div class="contentBoxWrapper"> <div id="home" class="contentBox"> <h1>Home</h1> <p>This will be the home page</p> </div> <div id="shop" class="contentBox"> <h1>Shop</h1> <p>This will be the shop page</p> </div> <div id="contact" class="contentBox"> <h1>Contact</h1> <p>This will be the contact page</p> </div> </div> </div> </div> <div id="title"></div> <div id="controlContainer"></div> </body> </html>
Create an account or sign in to comment