Difference between revisions of "Team:Cambridge-JIC/TestHome"
(8 intermediate revisions by the same user not shown) | |||
Line 12: | Line 12: | ||
#sidebar { | #sidebar { | ||
position:fixed; | position:fixed; | ||
− | top: | + | top:130px; |
− | + | right:20px; | |
width: 23px; | width: 23px; | ||
+ | z-index:1; | ||
} | } | ||
Line 24: | Line 25: | ||
border: #555 solid; | border: #555 solid; | ||
margin-bottom: 5px; | margin-bottom: 5px; | ||
+ | cursor:pointer; | ||
} | } | ||
</style> | </style> | ||
Line 42: | Line 44: | ||
$(window).on("resize", function(){ | $(window).on("resize", function(){ | ||
− | $("#sidebar").offset({ | + | $("#sidebar").offset({right: $(".cam-container section:first-of-type div").offset().right - 30}) |
if($(".navbar-collapse").is(":visible")) { | if($(".navbar-collapse").is(":visible")) { | ||
$(".downarrow").show() | $(".downarrow").show() | ||
+ | $("#sidebar").show() | ||
} else { | } else { | ||
$(".downarrow").hide() | $(".downarrow").hide() | ||
+ | $("#sidebar").hide() | ||
} | } | ||
}).resize(); | }).resize(); | ||
+ | var ix = 0; | ||
$("section").each(function(){ | $("section").each(function(){ | ||
if($(this).attr("id") != "footer-sec") { | if($(this).attr("id") != "footer-sec") { | ||
− | $("#sidebar").append("<div class=\"sidebar-item\"></div>") | + | $("#sidebar").append("<div onclick=\"scrollsection("+ix+")\" class=\"sidebar-item\""+(ix==0?" style=\"background: #555\"":"")+"></div>") |
} | } | ||
+ | ix++ | ||
}) | }) | ||
Line 63: | Line 69: | ||
var i=0; | var i=0; | ||
$("section").each(function(){ | $("section").each(function(){ | ||
− | if($(this).offset().top < $(window).scrollTop()) { | + | if($(this).offset().top <= $(window).scrollTop()) { |
$(".sidebar-item").css("background", "none") | $(".sidebar-item").css("background", "none") | ||
$($(".sidebar-item").get(i)).css("background", "#555") | $($(".sidebar-item").get(i)).css("background", "#555") | ||
Line 69: | Line 75: | ||
i++; | i++; | ||
}) | }) | ||
− | } | + | }) |
$(window).on("scroll", function(){ | $(window).on("scroll", function(){ | ||
Line 81: | Line 87: | ||
}); | }); | ||
+ | |||
+ | function scrollsection(id) { | ||
+ | $("html, body").animate({ scrollTop: $($("section").get(id)).offset().top }, 1000); | ||
+ | } | ||
</script> | </script> | ||
<div id="sidebar"></div> | <div id="sidebar"></div> |
Latest revision as of 02:18, 4 August 2015