Skip to content

Instantly share code, notes, and snippets.

@dstyle0210
Created July 28, 2014 04:44
Show Gist options
  • Select an option

  • Save dstyle0210/6f3b954106726d2f1473 to your computer and use it in GitHub Desktop.

Select an option

Save dstyle0210/6f3b954106726d2f1473 to your computer and use it in GitHub Desktop.
이미지 랜덤으로 뿌리기, 단 이전 이미지를 기억하여 똑같이 보이지는 않도록.
//<![CDATA[
$(function(){
var $wrap = $("#js-section0101");
var imageArr = ["/asan/images/main/section0101_bg.png", "/asan/images/main/section0101_bg2.png", "/asan/images/main/section0101_bg3.png"];
var oldNum;
var num = ~~(Math.random()*imageArr.length);
if(window.localStorage){
oldNum = Number(window.localStorage.getItem('section0101_ranomNum'));
while(oldNum === num){
num = ~~(Math.random()*imageArr.length);
}
}
window.localStorage && window.localStorage.setItem('section0101_ranomNum', num);
$wrap.css("background-image", "url("+imageArr[num]+")");
});
//]]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment