1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

See if the user has scrolled past a certain point?

Discussion in 'JavaScript' started by bigrollerdave, Aug 4, 2010.

  1. #1
    Okay I will try to explain this as best as I can...

    I have a layout that has 2 parts

    Left Navigation and Main Content

    The main content part of the page is a lot longer in the left nav. So once you scroll down a little bit the left nav is no where to be found but the main content continues to scroll.

    I was wondering if there was a way to see if the user has scrolled past the left nav part using javascript?

    My idea is once they scroll past the left nav I will place an adsense ad where the left nav should be and make it static. So when the user continues to scroll my adsense ad will be in the same place the whole time.
     
    bigrollerdave, Aug 4, 2010 IP
  2. usasportstraining

    usasportstraining Notable Member

    Messages:
    4,876
    Likes Received:
    363
    Best Answers:
    0
    Trophy Points:
    280
    Articles:
    4
    #2
    It would be better to create individual pages. Have a progressively more enticing, big link to the next page, etc.

    You could easily track the visitors from page to page.
     
    usasportstraining, Aug 4, 2010 IP
  3. bigrollerdave

    bigrollerdave Well-Known Member

    Messages:
    2,112
    Likes Received:
    52
    Best Answers:
    0
    Trophy Points:
    140
    #3
    Thanks for the help but I figured it out. When a user scrolls past the left navigation I set the ad to fixed and it will stay on the screen no matter how far down the user scrolls. Once the user scrolls back up and the left nav is shown again the ad will slide back into place where it belongs. Here is the code I used if anyone is interested.


    
    <script type="text/javascript" language="javascript">
    	window.onscroll = checkScroll;
    	
    	function checkScroll(event){
    		if(getScrollXY() >= 1200){
    			document.getElementById('leftAd').style.position="fixed";
    			document.getElementById('leftAd').style.top="100px";
    		} else {
    			if(document.getElementById('leftAd').style.position == "fixed"){
    				document.getElementById('leftAd').style.position="";
    				document.getElementById('leftAd').style.top="";
    				document.getElementById('leftAd').style.left="";
    			}
    		}
    	}
    	
    	
    	function getScrollXY() {
    		var scrOfY = 0;
    		if(typeof(window.pageYOffset) == 'number'){
    			scrOfY = window.pageYOffset;
    		} else if(document.body && (document.body.scrollLeft || document.body.scrollTop)){
    			scrOfY = document.body.scrollTop;
    		} else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)){
    			scrOfY = document.documentElement.scrollTop;
    		}
    		return scrOfY;
    	}
    
    </script>
    
    Code (markup):
    That's the javascript that will check to see how far down the user has scrolled

    <div id="leftAd">ADSENSE CODE HERE</div>
    Code (markup):
    That's the div that will change location based on how far the user has scrolled
     
    Last edited: Aug 4, 2010
    bigrollerdave, Aug 4, 2010 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Why don't you just have ads all the way down, after the navigation bar, rather than just one lonely one at the top?
     
    camjohnson95, Aug 5, 2010 IP
  5. bigrollerdave

    bigrollerdave Well-Known Member

    Messages:
    2,112
    Likes Received:
    52
    Best Answers:
    0
    Trophy Points:
    140
    #5
    Well google only allows 3 ads per page. Also what I've noticed is the more ads you have on a page the worse your CPC is. Not to mention the space from the bottom of the left nav to the footer is well over 2000px so I would need a bunch of ads there to fill the gap. I think the way I went about doing it is a lot more user friendly and I don't need to have ads all over the place. With just 1 ad I can place it in the left nav and it looks good. When the user scrolls down the ad will follow them and it still looks good. Not to mention that the adsense ad is always in their sight so it increases the CTR.
     
    bigrollerdave, Aug 5, 2010 IP
    camjohnson95 likes this.
  6. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #6
    I didn't know either of those facts. But it is good to know if I use adsense in the future.
     
    camjohnson95, Aug 6, 2010 IP