Click here to Skip to main content
15,888,803 members
Home / Discussions / JavaScript
   

JavaScript

 
QuestionDownload images from bing to use without internet connection Pin
Member 1301427820-Feb-17 23:42
Member 1301427820-Feb-17 23:42 
AnswerRe: Download images from bing to use without internet connection Pin
OriginalGriff20-Feb-17 23:44
mveOriginalGriff20-Feb-17 23:44 
GeneralRe: Download images from bing to use without internet connection Pin
Member 1301427820-Feb-17 23:49
Member 1301427820-Feb-17 23:49 
AnswerRe: Download images from bing to use without internet connection Pin
ZurdoDev21-Feb-17 2:01
professionalZurdoDev21-Feb-17 2:01 
Questionangular-cli chrome extension bootstrap from many .html Pin
JulioGold19-Feb-17 8:29
JulioGold19-Feb-17 8:29 
Questionremoving duplicates from array in order to use regex to find match. returning null Pin
Member 1299542016-Feb-17 16:26
Member 1299542016-Feb-17 16:26 
AnswerRe: removing duplicates from array in order to use regex to find match. returning null Pin
Nathan Minier17-Feb-17 1:31
professionalNathan Minier17-Feb-17 1:31 
QuestionAJAX request for photos Pin
Member 1300611016-Feb-17 11:06
Member 1300611016-Feb-17 11:06 
I wanted to take this code and change the image.src and make it into an ajax request or something like that to have the source for the photos be a user's flickr photos. I tried doing this on my own using the flickr api, but it wouldn't work. Does anyone know how I could do this? Thanks!


JavaScript code is pasted below from this person's code pen:
Infinite Scroll + Pagination[^]


function getPageId(n) {
	return 'article-page-' + n;
}

function getDocumentHeight() {
	const body = document.body;
	const html = document.documentElement;
	
	return Math.max(
		body.scrollHeight, body.offsetHeight,
		html.clientHeight, html.scrollHeight, html.offsetHeight
	);
};

function getScrollTop() {
	return (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
}

function getArticleImage() {
	const hash = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
	const image = new Image;
	image.className = 'article-list__item__image article-list__item__image--loading';
	image.src = 'http://api.adorable.io/avatars/250/' + hash;
	
	image.onload = function() {
		image.classList.remove('article-list__item__image--loading');
	};
	
	return image;
}

function getArticle() {
	const articleImage = getArticleImage();
	const article = document.createElement('article');
	article.className = 'article-list__item';
	article.appendChild(articleImage);
	
	return article;
}

function getArticlePage(page, articlesPerPage = 16) {
	const pageElement = document.createElement('div');
	pageElement.id = getPageId(page);
	pageElement.className = 'article-list__page';
	
	while (articlesPerPage--) {
		pageElement.appendChild(getArticle());
	}
	
	return pageElement;
}

function addPaginationPage(page) {
	const pageLink = document.createElement('a');
	pageLink.href = '#' + getPageId(page);
	pageLink.innerHTML = page;
	
	const listItem = document.createElement('li');
	listItem.className = 'article-list__pagination__item';
	listItem.appendChild(pageLink);
	
	articleListPagination.appendChild(listItem);
	
	if (page === 2) {
		articleListPagination.classList.remove('article-list__pagination--inactive');
	}
}

function fetchPage(page) {
	articleList.appendChild(getArticlePage(page));
}

function addPage(page) {
	fetchPage(page);
	addPaginationPage(page);
}

const articleList = document.getElementById('article-list');
const articleListPagination = document.getElementById('article-list-pagination');
let page = 0;

addPage(++page);

window.onscroll = function() {
	if (getScrollTop() < getDocumentHeight() - window.innerHeight) return;
	addPage(++page);
};

QuestionDynamically add row by DIV(SOLVED) Pin
samflex16-Feb-17 5:46
samflex16-Feb-17 5:46 
AnswerRe: Dynamically add row by DIV Pin
Richard Deeming16-Feb-17 8:40
mveRichard Deeming16-Feb-17 8:40 
GeneralRe: Dynamically add row by DIV Pin
samflex16-Feb-17 9:05
samflex16-Feb-17 9:05 
GeneralRe: Dynamically add row by DIV Pin
Richard Deeming16-Feb-17 9:30
mveRichard Deeming16-Feb-17 9:30 
GeneralRe: Dynamically add row by DIV Pin
samflex16-Feb-17 9:39
samflex16-Feb-17 9:39 
GeneralRe: Dynamically add row by DIV Pin
Richard Deeming16-Feb-17 10:12
mveRichard Deeming16-Feb-17 10:12 
GeneralRe: Dynamically add row by DIV Pin
samflex16-Feb-17 10:27
samflex16-Feb-17 10:27 
GeneralRe: Dynamically add row by DIV Pin
samflex16-Feb-17 10:52
samflex16-Feb-17 10:52 
GeneralRe: Dynamically add row by DIV Pin
Richard Deeming17-Feb-17 2:07
mveRichard Deeming17-Feb-17 2:07 
GeneralRe: Dynamically add row by DIV Pin
samflex17-Feb-17 2:53
samflex17-Feb-17 2:53 
QuestionInheriting a Javascript Prototype for Web Usercontrol Pin
HemeshSoni13-Feb-17 5:27
HemeshSoni13-Feb-17 5:27 
AnswerRe: Inheriting a Javascript Prototype for Web Usercontrol Pin
Richard Deeming13-Feb-17 8:06
mveRichard Deeming13-Feb-17 8:06 
GeneralRe: Inheriting a Javascript Prototype for Web Usercontrol Pin
HemeshSoni13-Feb-17 17:18
HemeshSoni13-Feb-17 17:18 
AnswerRe: Inheriting a Javascript Prototype for Web Usercontrol Pin
HemeshSoni13-Feb-17 17:25
HemeshSoni13-Feb-17 17:25 
Questionmvc app with angular not working in IIS on 80 port Pin
Member 1103130413-Feb-17 0:17
Member 1103130413-Feb-17 0:17 
AnswerRe: mvc app with angular not working in IIS on 80 port Pin
Nathan Minier13-Feb-17 0:54
professionalNathan Minier13-Feb-17 0:54 
GeneralRe: mvc app with angular not working in IIS on 80 port Pin
Member 1103130413-Feb-17 1:04
Member 1103130413-Feb-17 1:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.