$("body").animate({"scrollTop":top})无效的问题

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/lewky_liu/article/details/89774803

问题

我在个人站点的左下角和右下角各自使用了如下代码来将页面滚动到顶部和底部:

$("body").animate({scrollTop:0},800);

$("body").animate({scrollTop:$(document).height()},800);

最近才忽然发现在Chrome浏览器下,上面的代码没有问题,而在Firefox下却是无效的。百度后才知道,原来这是因为这两个浏览器自身的问题导致的。

对于Chrome而言,支持的是这种写法:

$("body".animate({"scrollTop":top});

而对于Firefox,则是支持如下写法:

$("html").animate({"scrollTop":top});

之前就一直耳闻前端开发需要兼容不同浏览器,非常地麻烦,今天算是见识到了冰山一角。

解决方法

既然这两个浏览器各自支持一种标签选择器,那么只要把两者统合起来即可实现兼容:

$("html,body".animate({"scrollTop":top});

最终,将我的代码改成如下形式便没问题了:

$("html,body").animate({scrollTop:0},800);

$("html,body").animate({scrollTop:$(document).height()},800);

参考链接

展开阅读全文

SpringData 使用 Top First 无效问题

12-29

想使用SpringData 查询前10条最新记录,也想使用以下Top 全局修饰符,结果报了一个空指针!rn我的Repository接口中的方法:public Book findTop10ByOrderByCreateTimeDesc();rn然后是异常:rnjava.lang.IllegalStateException: Failed to load ApplicationContextrn at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)rn at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)rn at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)rn at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)rn at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:217)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:276)rn at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:278)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:236)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)rn at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)rn at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)rn at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)rn at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)rn at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)rn at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)rn at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)rn at org.junit.runners.ParentRunner.run(ParentRunner.java:300)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)rn at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)rn at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)rnCaused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.huel.beasp.repository.book.BookRepository org.huel.beasp.service.book.BookService.bookRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookRepository': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerExceptionrn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)rn at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125)rn at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)rn at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109)rn at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261)rn at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)rn at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)rn ... 25 morernCaused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.huel.beasp.repository.book.BookRepository org.huel.beasp.service.book.BookService.bookRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookRepository': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerExceptionrn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:571)rn at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)rn ... 41 morernCaused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookRepository': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerExceptionrn at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175)rn at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1574)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:316)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1145)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1069)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:967)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:543)rn ... 43 morern下面还有...rnrnrn 论坛

没有更多推荐了,返回首页