mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2024-12-15 06:09:58 +08:00
Layout tiny tweaks
This commit is contained in:
parent
b8b8a8493c
commit
bd86b7936a
17
resources/assets/src/scripts/home-page.ts
Normal file
17
resources/assets/src/scripts/home-page.ts
Normal file
@ -0,0 +1,17 @@
|
||||
function handler() {
|
||||
const header = document.querySelector('.main-header')
|
||||
/* istanbul ignore else */
|
||||
if (header) {
|
||||
window.addEventListener('scroll', () => {
|
||||
if (window.scrollY >= window.innerHeight * 2 / 3) {
|
||||
header.classList.remove('transparent')
|
||||
} else {
|
||||
header.classList.add('transparent')
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('load', handler)
|
||||
|
||||
export default handler
|
@ -1,7 +1,10 @@
|
||||
export default [
|
||||
{
|
||||
path: '/',
|
||||
module: [() => import('../styles/home.styl')],
|
||||
module: [
|
||||
() => import('../styles/home.styl'),
|
||||
() => import('./home-page'),
|
||||
],
|
||||
},
|
||||
{
|
||||
path: 'user',
|
||||
|
21
resources/assets/tests/scripts/home-page.test.ts
Normal file
21
resources/assets/tests/scripts/home-page.test.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import handler from '@/scripts/home-page'
|
||||
|
||||
test('should be transparent at top', () => {
|
||||
Object.assign(window, { innerHeight: 900 })
|
||||
document.body.innerHTML = '<header class="main-header"></header>'
|
||||
handler()
|
||||
window.dispatchEvent(new Event('scroll'))
|
||||
expect(
|
||||
document.querySelector('header')!.classList.contains('transparent')
|
||||
).toBeTrue()
|
||||
})
|
||||
|
||||
test('should not be transparent at bottom', () => {
|
||||
Object.assign(window, { innerHeight: 900, scrollY: 800 })
|
||||
document.body.innerHTML = '<header class="main-header transparent"></header>'
|
||||
handler()
|
||||
window.dispatchEvent(new Event('scroll'))
|
||||
expect(
|
||||
document.querySelector('header')!.classList.contains('transparent')
|
||||
).toBeFalse()
|
||||
})
|
@ -3,7 +3,6 @@
|
||||
@section('title', trans('general.dashboard'))
|
||||
|
||||
@section('content')
|
||||
<style>.info-box > a { color: #333; }</style>
|
||||
<!-- Content Wrapper. Contains page content -->
|
||||
<div class="content-wrapper">
|
||||
<!-- Content Header (Page header) -->
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
<body class="hold-transition {{ option('color_scheme') }} layout-top-nav">
|
||||
|
||||
<div class="hp-wrapper" style="background-image: url('{{ $home_pic_url }}');">
|
||||
<div class="hp-wrapper" style="background-image: url('{{ $home_pic_url }}'); height: 100vh;">
|
||||
<!-- Navigation -->
|
||||
<header class="main-header transparent">
|
||||
<nav class="navbar navbar-fixed-top">
|
||||
@ -127,72 +127,5 @@
|
||||
|
||||
<!-- App Scripts -->
|
||||
@include('common.dependencies.script')
|
||||
|
||||
<script>
|
||||
function isMobileBrowserScrolling() {
|
||||
var currentWindowWidth = $(window).width();
|
||||
var currentWindowHeight = $(window).height();
|
||||
|
||||
if ($.cachedWindowWidth === undefined) {
|
||||
$.cachedWindowWidth = currentWindowWidth;
|
||||
}
|
||||
|
||||
if ($.cachedWindowHeight === undefined) {
|
||||
$.cachedWindowHeight = currentWindowHeight;
|
||||
}
|
||||
|
||||
var isWidthChanged = (currentWindowWidth !== $.cachedWindowWidth);
|
||||
var isHeightChanged = (currentWindowHeight !== $.cachedWindowHeight);
|
||||
|
||||
// If the window width & height changes simultaneously, the resize can't be fired by scrolling.
|
||||
if (isWidthChanged && isHeightChanged) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If only width was changed, it also can't be.
|
||||
if (isWidthChanged) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If width didn't change but height changed ?
|
||||
if (isHeightChanged) {
|
||||
var last = $.lastWindowHeight;
|
||||
$.lastWindowHeight = currentWindowHeight;
|
||||
|
||||
if (last === undefined || currentWindowHeight === last) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// If both width & height did not change
|
||||
return false;
|
||||
}
|
||||
|
||||
function changeWrapperHeight() {
|
||||
var btn = $('p a.button');
|
||||
var bottom = btn.offset().top + btn.height() + 80;
|
||||
|
||||
if (bottom > $(window).height()) {
|
||||
$('.hp-wrapper').height(bottom + 'px');
|
||||
} else {
|
||||
$('.hp-wrapper').height($(window).height() + 'px');
|
||||
}
|
||||
}
|
||||
|
||||
function changeHeaderTransparency() {
|
||||
if ($(window).scrollTop() >= ($(window).height() * 2 / 3)) {
|
||||
$('.main-header').removeClass('transparent');
|
||||
} else {
|
||||
$('.main-header').addClass('transparent');
|
||||
}
|
||||
}
|
||||
|
||||
$(window)
|
||||
.scroll(changeHeaderTransparency)
|
||||
.ready(changeWrapperHeight)
|
||||
.resize(function () {
|
||||
isMobileBrowserScrolling() ? null : changeWrapperHeight();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -87,11 +87,5 @@
|
||||
@include('common.dependencies.script')
|
||||
|
||||
@yield('script')
|
||||
|
||||
<script>
|
||||
if ($('.navbar').height() > 50) {
|
||||
$('.description-text').hide();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user