- This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
Viewing 2 posts - 1 through 2 (of 2 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Change Dynamic Page Script So I Can Reference A Tags to Trigger Change
I’ve Been Using This Script For This Tutorial https://css-tricks.com/rethinking-dynamic-page-replacing-content/
But Is There Any Way That I Can Change It So That The Change Can Be Trigger with any anchor tag no matter where it is on the page, and also could you just make a class like so that you could make only work on some links.
”’
$(function() {
if(Modernizr.history){
var newHash = "",
$mainContent = $("#main-content"),
$pageWrap = $("#page-wrap"),
baseHeight = 0,
$el;
$pageWrap.height($pageWrap.height());
baseHeight = $pageWrap.height() - $mainContent.height();
$("nav").delegate("a", "click", function() {
_link = $(this).attr("href");
history.pushState(null, null, _link);
loadContent(_link);
return false;
});
function loadContent(href){
$mainContent
.find("#guts")
.fadeOut(200, function() {
$mainContent.hide().load(href + " #guts", function() {
$mainContent.fadeIn(200, function() {
});
$("nav a").removeClass("current");
console.log(href);
$("nav a[href$="+href+"]").addClass("current");
});
});
}
$(window).bind('popstate', function(){
_link = location.pathname.replace(/^.*[\\\/]/, ''); //get filename only
loadContent(_link);
});
} // otherwise, history is not supported, so nothing fancy here.
});
”’
I use the same script, and have changed $(“nav”) to $(“document”) so that it works on any links rather than just those within a nav element.