Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-24-2012, 12:40 AM   PM User | #1
ktrevelae
New to the CF scene

 
Join Date: Aug 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
ktrevelae is an unknown quantity at this point
Question Javascript content load, screenview to resolve at top of the page

Hi,

I'm looking for help customizing some JavaScript. I'm primarily a web designer and I recently added some JavaScript to my portfolio website.

http://www.revelae.com/spotlight.html

When you click on the "more" boxes, the page loads in additional content.
Everything works great, but I want the content to "load" while bringing the screenview back up to the top of the page after each click.

I think this is a pretty quick fix, I just need to add something extra to my current JavaScript code. Any help on what to add is greatly appreciated!

Here's the code:
<script type="text/javascript">
ajax.pages = new Array();
ajax.pages["spotlight-main"] = "spotlight-main.html";
ajax.pages["spotlight-royal-rompers"] = "spotlight-royal-rompers.html";
ajax.pages["spotlight-trievas-spa"] = "spotlight-trievas-spa.html";
ajax.checkHash = function()
{
var windowHash = window.location.hash.replace("#", "");
windowHash = (windowHash == "") ? "spotlight-main" : windowHash;
if(windowHash != ajax.currentHash)
{
ajax.setHash(windowHash);
}
}
</script>


-Katie
ktrevelae is offline   Reply With Quote
Old 08-24-2012, 12:57 AM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
I'm not sure what I'm supposed to be clicking - I can't click the word 'More..'.

But I can't see that you have a method called setHash() that you are calling..?

I note an error message "404, not found" for:

Code:
http://www.revelae.com/menu.html
Have you uploaded this file correctly.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 08-24-2012, 01:08 AM   PM User | #3
ktrevelae
New to the CF scene

 
Join Date: Aug 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
ktrevelae is an unknown quantity at this point
The idea is to click on the thumbnail image boxes below More... and the page content will change.

The menu is an old file, not used anymore. Thanks for pointing that out. I've removed it.

I'm not sure about the set hash thing, This is a 3rd party script, and I'm not to the point of being able to code JavaScript yet.

I just want the content to load within the page (Which it currently does after clicking each More: thumbnail image) and bring the view to the top of the page, as the new content is displayed.

Last edited by ktrevelae; 08-24-2012 at 01:17 AM..
ktrevelae is offline   Reply With Quote
Old 08-24-2012, 01:25 AM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Okay, I see that setHash is defined in the file swap.js.

I suppose you can just scroll to the top of the page every time the page is (re)loaded. I understand that the following should/might work

Code:
function init(){
        $("#logobar").load("logobar.html");
        $("#footer").load("footer.html");
        $("#sidebar-right").load("spotlight-sidebar-right.html");
		$("#side-breakout").load("side-breakout.html");
        $(window).scrollTop(0);
      }
      $(document).ready(init);
But I'm not convinced that this will work - you'll need to try it.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS

Last edited by AndrewGSW; 08-24-2012 at 01:28 AM..
AndrewGSW is offline   Reply With Quote
Old 08-24-2012, 03:39 AM   PM User | #5
ktrevelae
New to the CF scene

 
Join Date: Aug 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
ktrevelae is an unknown quantity at this point
Hi,

$(window).scrollTop(0); doesn't work because all those structural elements load on page load, and the page script loads the page content without reloading the page.

I have tried using anchor tags to direct the page view on click, but the script either ignores the anchor tags or they break the page, depending on where placed.
ktrevelae is offline   Reply With Quote
Old 08-28-2012, 12:58 AM   PM User | #6
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Try editing the file swap.js as follows:

Code:
// This is the core of the script, that actually loads the content for the link that has been clicked
ajax.loadPage = function(hash)
{
	$("#sort").load(ajax.pages[hash] + " #sort", function () {
         $(window).scrollTop(0);
    });
}
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Users who have thanked AndrewGSW for this post:
ktrevelae (08-28-2012)
Old 08-28-2012, 01:02 AM   PM User | #7
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
.. if that works you might like:

Code:
// This is the core of the script, that actually loads the content for the link that has been clicked
ajax.loadPage = function(hash)
{
	$("#sort").load(ajax.pages[hash] + " #sort", function () {
         $('html, body').animate({scrollTop: 0}, 'slow');
    });
}
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 08-28-2012, 02:15 AM   PM User | #8
ktrevelae
New to the CF scene

 
Join Date: Aug 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
ktrevelae is an unknown quantity at this point
Thank you!!!!! It works great
ktrevelae is offline   Reply With Quote
Reply

Bookmarks

Tags
array load, javascript help

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:03 AM.


Advertisement
Log in to turn off these ads.