Я пытаюсь обновить разные изображения, когда одно из них попадает в определенные части страницы (используя это руководство в качестве основы: 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
Как вызвать функцию, если .call() не определен? ⇐ Jquery
Программирование на jquery
-
Anonymous
1714094822
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()
})()
Подробнее здесь: [url]https://stackoverflow.com/questions/78387828/how-do-i-call-function-if-call-is-undefined[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия