Skip to content

Instantly share code, notes, and snippets.

@hisasann
Created March 25, 2009 14:23
Show Gist options
  • Save hisasann/85492 to your computer and use it in GitHub Desktop.
Save hisasann/85492 to your computer and use it in GitHub Desktop.
(function($){
/*
* kingubonbi
*
* Date: 2008/08/23
* @author hisasann
* @version 0.1
*
* Tested with jQuery 1.2.6
* On FF 3.0, Opera 9.5 and Safari 3.1 on Mac OS X.
* IE6.0, IE7.0, FF 3.0, Opera 9.5 and Safari 3.1 on Windows.
*
* Copyright (c) 2008 hisasann (hisasann.com/housetect/)
* Open source under the BSD License.
*
*/
var opts = null;
$.kingbonbi = function(options){
opts = options;
$("<div id='kingbonbi-frame'></div>")
.css({
overflow: "hidden",
width: $(window).width() + "px",
height: $(window).height() + "px",
position: "absolute",
top: $(window).scrollTop() + "px",
left: $(window).scrollLeft() + "px",
backgroundColor: "#000000",
opacity: 0,
zIndex: 5000
})
.appendTo("body");
// Small Kingbonbi用の箱
$("<div id='kingbonbi-wrap'></div>")
.css({
overflow: "hidden",
width: $(window).width() + "px",
height: $(window).height() + "px",
position: "absolute",
top: $(window).scrollTop() + "px",
left: $(window).scrollLeft() + "px",
zIndex: 5001
})
.appendTo("body");
// Big Kingbonbi用の箱
$("<div id='kingbonbi-big-wrap'></div>")
.css({
overflow: "hidden",
width: $(window).width() + "px",
height: $(window).height() + "px",
position: "absolute",
top: $(window).scrollTop() + "px",
left: $(window).scrollLeft() + "px",
zIndex: 5002
})
.appendTo("body");
// Big Kingbonbi
$("<img src='"+ opts.big.src +"' alt='"+ opts.big.alt +"' width='"+ opts.big.width +"' height='"+ opts.big.height +"' />")
.attr("id", "kingbonbiBig")
.css({
position: "absolute",
cursor: "pointer",
top: "-" + opts.big.height,
zIndex: 5030
})
.click(function() {
$("#kingbonbi-wrap")
.animate({opacity: "0"},{queue: true, duration: 2000, easing: "swing", complete: function(){
$("#kingbonbi-frame").remove();
$("#kingbonbi-wrap").remove();
}});
})
.appendTo("#kingbonbi-big-wrap");
$("#kingbonbiBig")
.css({
top: "-" + $("#kingbonbiBig").height() + "px",
display: "block"
});
// Small Kingbonbi
var kLeft = 0;
var kTop = 0;
for(var i=0; i<opts.bonbiCount; i++){
kLeft = Math.floor(Math.random() * $(window).width());
kTop = Math.floor(Math.random() * $(window).height());
$("<img src='"+ opts.small.src +"' alt='"+ opts.small.alt +"' width='"+ opts.small.width +"' height='"+ opts.small.height +"' />")
.attr("id", "kingbonbi"+i)
.css({
left: kLeft + "px",
top: "-" + opts.small.height,
position: "absolute",
zIndex: 5010
})
.appendTo('#kingbonbi-wrap');
animeDown("#kingbonbi"+i, kTop);
}
// Big Kingbonbiを動作させるタイミングを監視
var interval = setInterval(function (){
if(animeCount >= opts.bonbiCount){
clearInterval(interval);
animeCount = 0;
var left = Math.floor(($(window).width() - $("#kingbonbiBig").width()) / 2);
var top = Math.floor(($(window).height() - $("#kingbonbiBig").height()) / 2);
$("#kingbonbiBig")
.css({
"left": left + "px"
})
.animate({top: top + "px"},{queue: true, duration: 3000, easing: "easeOutElastic", complete: function(){
opts.callback();
}});
}
}
, 500);
}
// Small Kingbonbi用アニメーション
var animeCount = 0;
function animeDown(objStr, kTop){
var rand = (Math.random() * 100) * 100;
setTimeout(function(){
$(objStr)
.animate({top: kTop + "px"},{queue: true, duration: 3500, easing: "easeOutBounce", complete: function(){
animeCount++;
}});
}, rand);
}
function getScroll(){
return {
x: document.body.scrollLeft || document.documentElement.scrollLeft,
y: document.body.scrollTop || document.documentElement.scrollTop
};
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment