Как вызвать функцию, если .call() не определен?Jquery

Программирование на jquery
Ответить
Anonymous
 Как вызвать функцию, если .call() не определен?

Сообщение Anonymous »

Я пытаюсь обновить разные изображения, когда одно из них попадает в определенные части страницы (используя это руководство в качестве основы: https://github.com/the-pudding/how-to-implement- Scrollytelling/tree/master/demo/scrollstory).
Функция определения «шага» страницы, на которой вы находитесь, работает, но я получаю сообщение об ошибке: «Невозможно читать свойства неопределенного (чтение «вызова»)», когда я пытаюсь вызвать функцию. Кто-нибудь знает, как это исправить?
window.createGraphic = function(graphicSelector) {
var graphicEl = d3.select('.graphic')
var graphicVisEl = graphicEl.select('.graphic__vis')
var graphicProseEl = graphicEl.select('.graphic__prose')
var dv = document.getElementById('image')
var img = document.createElement("IMG")

// actions to take on each step of our scroll-driven story
var steps = [
function step0() {
// remove all child nodes
while (dv.hasChildNodes()) {
dv.removeChild(dv.lastChild);
}

img.src = "./img/spec_fic_pg_1.png";
img.width = "100%";
img.height = "auto";
dv.appendChild(img);
},

function step1() {
// remove all child nodes
while (dv.hasChildNodes()) {
dv.removeChild(dv.lastChild);
}

img.src = "./img/spec_fic-02.png";
img.width = "100%";
img.height = "auto";
dv.appendChild(img);
},
]

// update our img
function update(step) {
console.log(step);
steps[step].call();
}

Это связанный HTML:


Disaster Tourism:
The Deep South in 2100


Step 1
Step 2








(function() {

function scrollstory() {
// select elements using jQuery since it is a dependency
var $graphicEl = $('.graphic')
var $graphicVisEl = $graphicEl.find('.graphic__vis')

// viewport height
var viewportHeight = window.innerHeight
var halfViewportHeight = Math.floor(viewportHeight / 2)

// a global function creates and handles all the vis + updates
var graphic = createGraphic('.graphic')

// handle the fixed/static position of grahpic
var toggle = function(fixed, bottom) {
if (fixed) $graphicVisEl.addClass('is-fixed')
else $graphicVisEl.removeClass('is-fixed')

if (bottom) $graphicVisEl.addClass('is-bottom')
else $graphicVisEl.removeClass('is-bottom')
}

// callback function when scrollStory detects item to trigger
var handleItemFocus = function(event, item) {
var step = item.data.step
graphic.update(step)
}

// callback on scrollStory scroll event
// toggle fixed position
var handleContainerScroll = function(event) {
var bottom = false
var fixed = false

var bb = $graphicEl[0].getBoundingClientRect()
var bottomFromTop = bb.bottom - viewportHeight

if (bb.top < 0 && bottomFromTop > 0) {
bottom = false
fixed = true
} else if (bb.top < 0 && bottomFromTop < 0) {
bottom = true
fixed = false
}

toggle(fixed, bottom)
}

// instantiate scrollStory
$graphicEl.scrollStory({
contentSelector: '.trigger',
triggerOffset: halfViewportHeight,
itemfocus: handleItemFocus,
containerscroll: handleContainerScroll,
})
}

scrollstory()

})()




Подробнее здесь: https://stackoverflow.com/questions/783 ... -undefined
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Jquery»