바이올린 http://jsfiddle.net/chdhmphry/z8upoccm/jQuery로 시차 객체의 프로토 타입을 만들기 내가
내가 한 페이지에 여러 스크롤 상호 작용에 대해 "시차"프로토 타입을 만들려고하고 jQuery를 함수에 정의되지 않은 오류가 계속하지만, 내가 점점 계속 "catch되지 않은 형식 오류 : undefined는 12, 13, 35 행의 함수가 아닙니다. "저는 Prototypes에 익숙하지 않지만 jQuery는 프로토 타입과 잘 작동하지 않습니까? 오류없이 다른 영역의 다른 jquery 코드를 사용하고 있습니다. 요소와 상호 작용할 때만 사용됩니다.
Object.prototype.parallax = function(userOptions){
// Default info
var options = {
speed: 6,
direction: "down"
};
options = $.extend(options, userOptions);
// Element info
var element = this;
var startPoint = element.position().top;
var endPoint = element.position().top + element.height();
// Scroll info
var scrollPos = {
top: $(window).scrollTop(),
bottom: $(window).scrollTop() + $(window).height()
};
// first call
scrolling();
// call on scroll
$(window).on("scroll", function(){
scrolling();
});
function scrolling(){
scrollPos = {
top: $(window).scrollTop(),
bottom: $(window).scrollTop() + $(window).height()
};
element.css({"transform": "translateY("+(scrollPos.top - startPoint)+")"});
}
};
$("#js-new-title-stuck-3").parallax({speed:2});
고마워요!
는
! 고맙습니다! –