Mars Mobile Web Solutions
repository·master·Indexed 27 days ago
https://github.com/alloyteam/marsA collection of mobile-focused web solutions and tools for building high-performance, native-like web experiences. Mars provides guidance on CSS3 animations, high-performance scrolling, and offline web apps, alongside specialized libraries such as Omi, AlloyTouch, AlloyFinger, AlloyCrop, AlloyLever, and Cax. It includes comprehensive documentation for resolving iOS and Android compatibility issues, project structure best practices, and a curated list of mobile development tools.
What's inside Mars
- Mars provides a collection of solutions and tools designed for large-scale mobile Web development. It includes guidance on project structure, font settings, native-like effects, performance optimization, and a suite of specialized mobile libraries for touch, gestures, cropping, and error monitoring.
Access mobile development resources and tools
masterThetools/README.mdfile provides a curated list of external resources for mobile web development, including debugging tools, compatibility checkers, device specifications, and CSS/design utilities.High-performance Mobile Web Development Overview
masterMars provides resources and guides for achieving high-performance Mobile Web development. The core focus areas include:
- High-performance CSS3 animations: Techniques for smooth animations on mobile devices.
- CSS animation property performance: Understanding which CSS properties are optimized for animation.
- High-performance scrolling: Implementing smooth scrolling behaviors.
- Offline Web Apps: Implementing Service Workers for offline capabilities, message synchronization, and push notifications.
Remove zero-width space characters from input
masterIn some iOS versions, a special character (U+2006) may appear between English letters when using Chinese input methods. You can remove it using a regular expression:
this.value = this.value.replace(/\u2006/g, '');Improve touchmove performance with setTimeout
masterWhen handling heavy logic inside atouchmoveevent, the frame rate (FPS) may drop. Wrapping the logic in asetTimeoutwith a delay of0can improve perceived smoothness.Optimize CSS animation performance by avoiding Layout and Paint
masterTo achieve high-performance CSS animations (ideally 60fps), avoid animating properties that trigger Layout (reflow) or Paint (repaint). Animating such properties forces the browser to recalculate the geometry of the page and redraw pixels, which is computationally expensive.
Instead, use properties that only trigger Composite (recomposite). The most common and effective way to do this is by using
transform(e.g.,translateX,translateY,scale,rotate) instead of positional properties likeleft,top,margin, orwidth/height.Performance Comparison:
left/top: Triggers Layout $\rightarrow$ Paint $\rightarrow$ Composite (Slowest)transform: Triggers Composite only (Fastest)
Optimize font size adjustment on iOS and OS X
masteriOS browsers may reset font sizes when switching to landscape mode. To prevent inconsistent font weights and sizes, set
text-size-adjustto100%.-webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; text-size-adjust: 100%;Implement physical 1px borders using CSS3 transform
masterAn alternative method to achieve a fine 1px border without external images is to use a pseudo-element (
:after) and scale it down usingtransform: scale(0.5). This effectively halves the perceived thickness of the border on high-DPI screens.Implementation:
- Set the parent element to
position: relative. - Create an
:afterpseudo-element withposition: absoluteand negative offsets (e.g.,top: -50%,left: -50%, etc.) to cover the area. - Apply
transform: scale(0.5)to the pseudo-element. - Define the
border-topandborder-bottomon the pseudo-element.
.border-1px { position: relative; } .border-1px:after { position: absolute; content: ''; top: -50%; bottom: -50%; left: -50%; right: -50%; -webkit-transform: scale(0.5); transform: scale(0.5); border-top: 1px solid #666; border-bottom: 1px solid #666; }- Set the parent element to
Configure cross-platform font-family for web projects
masterTo ensure consistent typography across iOS, macOS, Windows, and Android, use a comprehensive font stack in your CSS. This stack prioritizes system fonts to match the native look and feel of each platform:
- iOS/macOS: Uses
-apple-systemandBlinkMacSystemFontfor native system fonts, falling back toHelvetica NeueorHelvetica. - Windows: Uses
Microsoft Yahei(微软雅黑) to avoid the low-quality appearance ofSimsunon high-resolution screens. - Android: Relies on the system's default sans-serif font (typically
Robotoon modern devices) to accommodate various manufacturer customizations. - Chinese Font Fallbacks: Includes
PingFang SC(简体苹方) andSTHeiti(华文黑体). Note thatSTHeitiacts as a fallback that triggers system defaults likeHeiti SCorHeiti TCon Apple devices.
body { font-family: -apple-system, BlinkMacSystemFont, "PingFang SC","Helvetica Neue",STHeiti,"Microsoft Yahei",Tahoma,Simsun,sans-serif; }- iOS/macOS: Uses
Optimize CSS3 animations using GPU acceleration
masterTo improve mobile animation smoothness and prevent stuttering, use 3D transforms to trigger hardware acceleration (GPU). This is significantly more performant than animating properties like
leftortop.Note: 3D transforms consume more memory and power; use them only when performance issues are present.
To prevent flickering at the start of an animation, apply the
backface-visibility: hiddenandperspectivehacks./* Enable GPU acceleration */ -webkit-transform: translate3d(0, 0, 0); -moz-transform: translate3d(0, 0, 0); -ms-transform: translate3d(0, 0, 0); transform: translate3d(0, 0, 0); /* Prevent flickering hack */ -webkit-backface-visibility: hidden; -moz-backface-visibility: hidden; -ms-backface-visibility: hidden; backface-visibility: hidden; -webkit-perspective: 1000; -moz-perspective: 1000; -ms-perspective: 1000; perspective: 1000;Reduce animation reflows and layout costs
masterTo ensure high-performance mobile web experiences, follow these CSS optimization rules:
- Avoid expensive properties: Minimize the use of
box-shadowsandgradients, as they are significant performance killers. Consider flat design instead. - Remove elements from document flow: Use
position: fixed;orposition: absolute;for animated elements to reduce the impact of reflows on the rest of the page.
- Avoid expensive properties: Minimize the use of
Remove IE10 input clear button
masterTo hide the default clear button (the 'X') in IE10 input elements, use the following CSS: