Merge pull request #98 from fuerst/master
Add background-position to bigimg's configurable per image.
This commit is contained in:
commit
729b60b71a
@ -25,6 +25,8 @@ pygmentCodeFences = true
|
|||||||
#[[Params.bigimg]]
|
#[[Params.bigimg]]
|
||||||
# src = "img/sphere.jpg"
|
# src = "img/sphere.jpg"
|
||||||
# desc = "Sphere"
|
# desc = "Sphere"
|
||||||
|
# # position: see values of CSS background-position.
|
||||||
|
# position = "center top"
|
||||||
#[[Params.bigimg]]
|
#[[Params.bigimg]]
|
||||||
# src = "img/hexagon.jpg"
|
# src = "img/hexagon.jpg"
|
||||||
# desc = "Hexagon"
|
# desc = "Hexagon"
|
||||||
|
@ -77,13 +77,15 @@ var main = {
|
|||||||
var imgInfo = main.getImgInfo();
|
var imgInfo = main.getImgInfo();
|
||||||
var src = imgInfo.src;
|
var src = imgInfo.src;
|
||||||
var desc = imgInfo.desc;
|
var desc = imgInfo.desc;
|
||||||
main.setImg(src, desc);
|
var position = imgInfo.position;
|
||||||
|
main.setImg(src, desc, position);
|
||||||
|
|
||||||
// For better UX, prefetch the next image so that it will already be loaded when we want to show it
|
// For better UX, prefetch the next image so that it will already be loaded when we want to show it
|
||||||
var getNextImg = function() {
|
var getNextImg = function() {
|
||||||
var imgInfo = main.getImgInfo();
|
var imgInfo = main.getImgInfo();
|
||||||
var src = imgInfo.src;
|
var src = imgInfo.src;
|
||||||
var desc = imgInfo.desc;
|
var desc = imgInfo.desc;
|
||||||
|
var position = imgInfo.position;
|
||||||
|
|
||||||
var prefetchImg = new Image();
|
var prefetchImg = new Image();
|
||||||
prefetchImg.src = src;
|
prefetchImg.src = src;
|
||||||
@ -91,13 +93,16 @@ var main = {
|
|||||||
|
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
var img = $("<div></div>").addClass("big-img-transition").css("background-image", 'url(' + src + ')');
|
var img = $("<div></div>").addClass("big-img-transition").css("background-image", 'url(' + src + ')');
|
||||||
|
if (position !== undefined) {
|
||||||
|
img.css("background-position", position);
|
||||||
|
}
|
||||||
$(".intro-header.big-img").prepend(img);
|
$(".intro-header.big-img").prepend(img);
|
||||||
setTimeout(function(){ img.css("opacity", "1"); }, 50);
|
setTimeout(function(){ img.css("opacity", "1"); }, 50);
|
||||||
|
|
||||||
// after the animation of fading in the new image is done, prefetch the next one
|
// after the animation of fading in the new image is done, prefetch the next one
|
||||||
//img.one("transitioned webkitTransitionEnd oTransitionEnd MSTransitionEnd", function(){
|
//img.one("transitioned webkitTransitionEnd oTransitionEnd MSTransitionEnd", function(){
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
main.setImg(src, desc);
|
main.setImg(src, desc, position);
|
||||||
img.remove();
|
img.remove();
|
||||||
getNextImg();
|
getNextImg();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
@ -116,15 +121,24 @@ var main = {
|
|||||||
var randNum = Math.floor((Math.random() * main.numImgs) + 1);
|
var randNum = Math.floor((Math.random() * main.numImgs) + 1);
|
||||||
var src = main.bigImgEl.attr("data-img-src-" + randNum);
|
var src = main.bigImgEl.attr("data-img-src-" + randNum);
|
||||||
var desc = main.bigImgEl.attr("data-img-desc-" + randNum);
|
var desc = main.bigImgEl.attr("data-img-desc-" + randNum);
|
||||||
|
var position = main.bigImgEl.attr("data-img-position-" + randNum);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
src : src,
|
src : src,
|
||||||
desc : desc
|
desc : desc,
|
||||||
|
position : position
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setImg : function(src, desc) {
|
setImg : function(src, desc, position) {
|
||||||
$(".intro-header.big-img").css("background-image", 'url(' + src + ')');
|
$(".intro-header.big-img").css("background-image", 'url(' + src + ')');
|
||||||
|
if (position !== undefined) {
|
||||||
|
$(".intro-header.big-img").css("background-position", position);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Remove background-position if added to the prev image.
|
||||||
|
$(".intro-header.big-img").css("background-position", "");
|
||||||
|
}
|
||||||
if (typeof desc !== typeof undefined && desc !== false) {
|
if (typeof desc !== typeof undefined && desc !== false) {
|
||||||
$(".img-desc").text(desc).show();
|
$(".img-desc").text(desc).show();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user