Investors brace for more 'Wal-Mart raises' 55 | (americasmarkets.usatoday.com)
56 | 57 |Wal-Mart workers just scored a raise. Now retail investors are 58 | wondering – are more pay hikes coming?
├── README.md ├── enablePanelSwipe.js ├── getPrefixedProperty.js ├── index.htm ├── normalize.css └── style.css /README.md: -------------------------------------------------------------------------------- 1 | # flipboard-style-dom 2 | Flipboard-style news reader using DOM for mobile. 60FPS 3 | 4 | * Works on iOS, Android 4+, Firefox, Windows Phone 8 5 | * Clone and open index.htm 6 | 7 | 8 | Demo: http://premii.com/play/flipboard-style-news/ -------------------------------------------------------------------------------- /enablePanelSwipe.js: -------------------------------------------------------------------------------- 1 | 2 | (function (window) { 3 | 4 | var helper = window.helper || (window.helper = {}); 5 | 6 | var prefixedTransform = helper.getPrefixedProperty('transform'); 7 | 8 | helper.closest = function (el, fn) { 9 | while (el) { 10 | if (fn(el)) { 11 | return el; 12 | } 13 | el = el.parentNode; 14 | } 15 | }; 16 | 17 | helper.pointerEventToXY = function(e){ 18 | var out = {x:0, y:0}; 19 | 20 | if (e.type.indexOf('touch') === 0) { 21 | var touch = e.touches[0] || e.changedTouches[0]; 22 | out.x = touch.pageX; 23 | out.y = touch.pageY; 24 | } 25 | else if (e.type.indexOf('mouse') === 0) { 26 | out.x = e.pageX; 27 | out.y = e.pageY; 28 | } 29 | return out; 30 | }; 31 | 32 | helper.easeOutQuad = function (t) { 33 | return t*(2-t); 34 | }; 35 | 36 | var animatePanels = function(topPanelOptions, bottomPanelOptions, availableDistance, availableDuration, direction, callback) { 37 | 38 | var topPanel = topPanelOptions.page, 39 | bottomPanel = bottomPanelOptions.page, 40 | topPanelEndPosition = topPanelOptions.endPosition, 41 | topPanelStartPosition = topPanelOptions.startPosition; 42 | 43 | var startTime = Date.now(), 44 | duration = availableDuration / availableDistance * Math.abs(topPanelStartPosition - topPanelEndPosition), 45 | currentY = topPanelStartPosition, 46 | frameCount = 0; 47 | 48 | 49 | direction = direction || 1; 50 | // console.warn('animatePages(): duration', duration); 51 | 52 | callback = callback || function () {}; 53 | 54 | var getBottomPanelYPosition = function(x, direction) { 55 | return (x - (availableDistance * direction)) / 2; 56 | }; 57 | 58 | topPanel.style.display = 'block'; 59 | bottomPanel.style.display = 'block'; 60 | 61 | var animate = function () { 62 | // console.log('animate()'); 63 | var currentTime = Date.now(), 64 | time = Math.min(1, ((currentTime - startTime) / duration)), 65 | easedT = helper.easeOutQuad(time); 66 | 67 | frameCount++; 68 | 69 | currentY = (easedT * (topPanelEndPosition - (topPanelStartPosition))) + topPanelStartPosition; 70 | 71 | topPanel.style[prefixedTransform] = 'translate3d(0, ' + (currentY) + 'px, 0)'; 72 | 73 | bottomPanel.style[prefixedTransform] = 'translate3d(0, ' + getBottomPanelYPosition(currentY, direction) + 'px, 0)'; 74 | 75 | if (time < 1 && ((direction === -1 && currentY < topPanelEndPosition) || (direction === 1 && currentY > topPanelEndPosition))) { 76 | window.requestAnimationFrame(animate); 77 | } 78 | else { 79 | callback({ 80 | frameCount: frameCount, 81 | time: +new Date - startTime 82 | }); 83 | } 84 | }; 85 | 86 | window.requestAnimationFrame(animate); 87 | }; 88 | 89 | var hideAllChildren = function(visibleItems) { 90 | var item, 91 | visibleChildIndex; 92 | 93 | visibleItems[0].classList.add('swipe-current'); 94 | 95 | for(var i = 0, len = visibleItems.length; i < len; i++) { 96 | item = visibleItems[i]; 97 | 98 | if (item.classList.contains('swipe-current')) { 99 | visibleChildIndex = i; 100 | if (i > 0) { 101 | visibleItems[i - 1].style.display = 'block'; //previous item visible 102 | } 103 | item.style.display = 'block'; //make current item visible 104 | } 105 | else { 106 | item.style.display = 'none'; //all other hidden 107 | } 108 | 109 | if (i == visibleChildIndex + 1) { 110 | item.style.display = 'block'; //make next item is visible 111 | item.style[prefixedTransform] = 'translate3d(0, 100%, 0)'; 112 | } 113 | else if (i == visibleChildIndex - 1) { 114 | item.style.display = 'block'; //make previous item is visible 115 | item.style[prefixedTransform] = 'translate3d(0, -100%, 0)'; 116 | } 117 | } 118 | }; 119 | 120 | var calculateTopPanelYPosition = function(visibleWindowHeight, bottomYPosition, direction) { 121 | direction = direction || 1; 122 | 123 | var topYPosition = (visibleWindowHeight * direction) + (bottomYPosition * 2); 124 | if (direction === 1) { 125 | if (topYPosition < 0) { 126 | topYPosition = 0; 127 | } 128 | } 129 | else if (direction === -1) { 130 | if (topYPosition > 0) { 131 | topYPosition = 0; 132 | } 133 | } 134 | 135 | return topYPosition; 136 | }; 137 | 138 | var enablePanelSwipe = function (option) { 139 | 140 | var scrollableOptions = {}; 141 | scrollableOptions.scrollRegion = option.scrollRegion; 142 | scrollableOptions.children = option.children; 143 | scrollableOptions.afterAnimationCallback = option.callback || function() {}; 144 | 145 | var swipeDirty = false, 146 | startXY, 147 | continueAnimation = 0, 148 | allowedTimePerPixel = 65/100, 149 | allowedTime = 350; // maximum allowed time to travel available distance (visiblePanelHeight) 150 | 151 | var isAnimating = false, 152 | swipeVerticalPossible = false, 153 | currentPanel, 154 | nextPanel, 155 | prevPanel, 156 | swipeToPanel, 157 | visiblePanelHeight, 158 | touchStartTime; 159 | 160 | var lastXY, 161 | panelPositions; 162 | 163 | var onTouchStart = function(event) { 164 | 165 | var target = event.target; 166 | 167 | if (!isAnimating && scrollableOptions.scrollRegion.contains(target)) { 168 | 169 | currentPanel = helper.closest(target, function (el) { 170 | return el.classList.contains('swipe-current'); 171 | }); 172 | 173 | if (currentPanel) { 174 | swipeVerticalPossible = true; 175 | 176 | touchStartTime = +new Date(); 177 | startXY = helper.pointerEventToXY(event); 178 | visiblePanelHeight = currentPanel.clientHeight; 179 | nextPanel = currentPanel.nextElementSibling; 180 | prevPanel = currentPanel.previousElementSibling; 181 | } 182 | } 183 | }; 184 | 185 | var cleanUpOnTouchEnd = function() { 186 | 187 | if (swipeDirty === 1) { 188 | if (prevPanel) { 189 | prevPanel.style.display = 'none'; 190 | } 191 | nextPanel = swipeToPanel.nextElementSibling; 192 | 193 | if (nextPanel) { 194 | nextPanel.style[prefixedTransform] = 'translate3d(0, 100%, 0)'; 195 | nextPanel.style.display = 'block'; 196 | } 197 | } 198 | else if (swipeDirty === -1) { 199 | 200 | if (nextPanel) { 201 | nextPanel.style.display = 'none'; 202 | } 203 | prevPanel = swipeToPanel.previousElementSibling; 204 | 205 | if (prevPanel) { 206 | prevPanel.style[prefixedTransform] = 'translate3d(0, -100%, 0)'; 207 | prevPanel.style.display = 'block'; 208 | } 209 | } 210 | 211 | if (swipeVerticalPossible && isAnimating) { 212 | scrollableOptions.afterAnimationCallback(swipeToPanel); 213 | } 214 | 215 | swipeVerticalPossible = false; 216 | 217 | isAnimating = false; 218 | nextPanel = null; 219 | prevPanel = null; 220 | currentPanel = null; 221 | 222 | swipeDirty = false; 223 | lastXY = null; 224 | 225 | }; 226 | 227 | var onTouchEnd = function(event) { 228 | 229 | if (swipeVerticalPossible && swipeDirty && !isAnimating) { 230 | 231 | swipeDirty = swipeDirty === 1 ? 1 : -1; 232 | 233 | allowedTime = visiblePanelHeight * allowedTimePerPixel; 234 | 235 | isAnimating = true; 236 | animatePanels({ 237 | page: swipeToPanel, 238 | startPosition: panelPositions.top, 239 | endPosition: 0 240 | }, 241 | { 242 | page: currentPanel, 243 | startPosition: panelPositions.bottom 244 | }, 245 | visiblePanelHeight, 246 | allowedTime, 247 | swipeDirty, 248 | function(op) { 249 | 250 | var bottomYPosition = (swipeDirty === 1) ? '-100%' : '100%'; 251 | currentPanel.style[prefixedTransform] = 'translate3d(0, ' + bottomYPosition + ', 0)'; 252 | 253 | currentPanel.classList.remove('swipe-current'); 254 | swipeToPanel.classList.add('swipe-current'); 255 | 256 | window.setTimeout(function() { 257 | swipeToPanel.querySelector('.fleft').innerHTML = op.frameCount + ' frames ' + ' / ' + op.time + 'ms'; 258 | }, 100); 259 | cleanUpOnTouchEnd(); 260 | }); 261 | 262 | } 263 | else if (!isAnimating) { 264 | cleanUpOnTouchEnd(); 265 | } 266 | 267 | }; 268 | 269 | 270 | var onTouchMove = function(event) { 271 | 272 | event.preventDefault(); 273 | 274 | if (isAnimating || !swipeVerticalPossible) { 275 | return; 276 | } 277 | 278 | lastXY = helper.pointerEventToXY(event); 279 | 280 | var swipeDiff = lastXY.y - startXY.y; 281 | 282 | if (Math.abs(swipeDiff) > 0) { 283 | 284 | if (swipeDiff > 0 && prevPanel) { 285 | swipeToPanel = prevPanel; 286 | swipeDirty = -1; 287 | } 288 | else if (swipeDiff < 0 && nextPanel) { 289 | swipeToPanel = nextPanel; 290 | swipeDirty = 1; 291 | } 292 | else { 293 | swipeToPanel = null; 294 | swipeDirty = 0; 295 | } 296 | 297 | if (swipeToPanel) { 298 | 299 | panelPositions = { 300 | bottom: swipeDiff, 301 | top: calculateTopPanelYPosition(visiblePanelHeight, swipeDiff, swipeDirty) 302 | }; 303 | 304 | currentPanel.style[prefixedTransform] = 'translate3d(0, ' + panelPositions.bottom + 'px, 0)'; 305 | currentPanel.style.zIndex = 1; 306 | 307 | swipeToPanel.style[prefixedTransform] = 'translate3d(0, ' + panelPositions.top + 'px, 0)'; 308 | swipeToPanel.style.zIndex = 2; 309 | } 310 | } 311 | }; 312 | 313 | // console.log(scrollableOptions.children); 314 | hideAllChildren(scrollableOptions.children); 315 | 316 | //Adding event everytime init gets called. May be add a check so only one event is added. 317 | 318 | scrollableOptions.scrollRegion.addEventListener('touchstart', onTouchStart, false); 319 | scrollableOptions.scrollRegion.addEventListener('touchmove', onTouchMove, false); 320 | scrollableOptions.scrollRegion.addEventListener('touchend', onTouchEnd, false); 321 | }; 322 | 323 | helper.enablePanelSwipe = enablePanelSwipe ; 324 | 325 | }(window)); 326 | -------------------------------------------------------------------------------- /getPrefixedProperty.js: -------------------------------------------------------------------------------- 1 | 2 | (function(window){ 3 | 4 | var helper = window.helper || (window.helper = {}); 5 | 6 | var prefixedProperties = {}; 7 | var testDiv = document.createElement('div'); 8 | var availablePrefixes = ["Webkit", "webkit", "ms", "Moz", "moz", "o", "O"]; 9 | 10 | var getPrefixedProperty = function (property) { 11 | 12 | var camelCaseProperty; 13 | if (!prefixedProperties[property]) { 14 | prefixedProperties[property] = property; 15 | 16 | if (typeof testDiv.style[property] === 'undefined') { 17 | camelCaseProperty = property.charAt(0).toUpperCase() + property.slice(1); 18 | 19 | for (var i = 0; i < availablePrefixes.length; i++) { 20 | if (typeof testDiv.style[availablePrefixes[i] + camelCaseProperty] !== "undefined") { 21 | availablePrefixes = [availablePrefixes[i]]; 22 | prefixedProperties[property] = availablePrefixes[i] + camelCaseProperty; 23 | break; 24 | } 25 | } 26 | } 27 | } 28 | 29 | return prefixedProperties[property]; 30 | }; 31 | 32 | helper.getPrefixedProperty = getPrefixedProperty; 33 | 34 | }(this)); 35 | -------------------------------------------------------------------------------- /index.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 |This app will download 40+ images. It will use roughly 27 MB of your bandwidth. Swipe up!
35 | 36 |Wal-Mart workers just scored a raise. Now retail investors are 58 | wondering – are more pay hikes coming?
The Department of Veterans Affairs has frozen the disabled 69 | veteran’s benefits until she pays back the full amount the VA mistakenly awarded for 70 | her wife and child.
ran could allow Internet giants such as Google to operate in the 81 | Islamic republic if they respect its 'cultural' rules, Fars news agency says
82 |Karma's a witch.
The trend has raised concerns in Va. and elsewhere because they 104 | often receive little training and oversight.
A Massachusetts teenager was facing a charge of involuntary 118 | manslaughter after allegedly encouraging her boyfriend to kill himself. Conrad Roy, 119 | 18, died of carbon monoxide poisoning while sitting i...
If not for cell phone video, 47-year-old disabled veteran Douglas 132 | Dendinger could be going to prison — because of an apparent coordinated effort by 133 | Washington Parish, La. cops and prosecutors who falsely accused him of battery and 134 | witness intimidation. As New Orleans’ WWL reports, Dendinger’s two-year nightmare 135 | began on Aug. 20, 2012, when he was paid $50 to serve a court summons on behalf of 136 | his nephew against Bogalusa police officer Chad Cassard in a police brutality 137 | lawsuit. Dendinger handed Cassard a white envelope containing the documents and says 138 | he went on his way. A year after the incident, then-District Attorney Walter Reed 139 | brought charges against Dendinger.
The school district provided about a third of the total money 152 | required to renovate the girls and boys basketball facilities at Arrowhead high 153 | school.
Samsung Galaxy S6 is designed to woo consumers from Apple's 164 | iPhone juggernaut, but the electronics giant also has a big pitch to businesses.
165 |A Brooklyn state senator apologized Tuesday for remarks invoking 178 | the subject of race in a discussion about a Clinton Hill grocery store set to close 179 | – and the possibility that a “boutique” grocery store that could replace it.
180 |Fox News now clarifies he saw photographs not actual 191 | violence.
Apple rarely comments on legal matters, and when it does it 212 | chooses its words carefully. So I read with interest the statement it issued after 213 | it was ordered to pay $532.9 million to Smartflash LLC...
Before he was shot and killed, Mr. Nemtsov had met with an old 226 | friend to discuss his latest research into what he said was dissembling and misdeeds 227 | in the Kremlin.
Video caught on camera the night of the shooting has been 241 | released to the media. KNOE will share that video online this afternoon and during 242 | our Thursday evening newscasts. A WARNING, the video posted on KNOE.COM is the 243 | non-blurred version and is graphic.
A weekend fraternity ski party gone wild damaged the resort's 254 | reputation as well as property, says its general manager.
First-ever rendezvous with the largest object in the asteroid 267 | belt separating Mars from Jupiter will reveal what Ceres is made of
There could be dozens of more Siberian craters out there.
278 |Crowd gathers outside facility at centre of claims of 291 | unconstitutional abuse with Anonymous and Black Lives Matter among the groups 292 | present
FEMA official says he has seen evidence of fraud in engineering 305 | reports used to deny thousands of Hurricane Sandy claims
Google researchers have created an algorithm that has a 316 | human-like ability to learn, marking a significant breakthrough in the field of 317 | artificial intelligence. In a paper published in Nature this week, the researchers 318 | demonstrated that the algorithm could master many Atari video games better than 319 | humans, simply through playing the game and learning from experience.
An internal memo from the Privy Council Office, Prime Minister 342 | Stephen Harper's department, sings the praises of "gamification," that is, 343 | encouraging workers to play computer games each day.
Ticks carrying the bacterium responsible for Lyme disease are 356 | infesting Northern California’s birds and may be hitching rides on them into 357 | suburban settings, according to a new UC Berkeley study.
A secondary school in Malmö has been closed after the teachers' 368 | union declared that it is too dangerous a place for students and teachers to attend 369 | due to widespread violence and criminality.